# Shift bezier curve as a whole in tikz

Is there an easy way to shift a bezier curve as a whole, e.g. 2cm in x-direction,1 cm in y-direction without changing the control points?

\documentclass[11pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\draw (0,0) .. controls (1,1) and (2,-1) .. (3,0);
\end{tikzpicture}
\end{document}


The xshift- and yshift-key don't seem to be usable for that. Thank you

Edit: As Guilherme pointed out the shift property works well:

\documentclass[11pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\draw (0,0) .. controls (1,1) and (2,-1) .. (3,0);
\draw[shift={(2cm,1cm)}] (0,0) .. controls (1,1) and (2,-1) .. (3,0);
\end{tikzpicture}
\end{document}


However it doesn't work when you define coordinates for the curve beforehand:

\documentclass[11pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\coordinate (A1) at (0,0);
\coordinate (A2) at (1,1);
\coordinate (A3) at (2,-1);
\coordinate (A4) at (3,0);

\draw (A1) .. controls (A2) and (A3) .. (A4);
\draw[shift={(2cm,1cm)}] (A1) .. controls (A2) and (A3) .. (A4);
\end{tikzpicture}
\end{document}


The second curve then doesn't move from its original position.

• \draw[shift={(2cm,1cm)}] (0,0) .. controls (1,1) and (2,-1) .. (3,0); should work – Guilherme Zanotelli Jan 19 '17 at 17:44
• Thanks for your answer. It doesn't work for me. – miga89 Jan 19 '17 at 17:48
• Well, why not? Do you get an error?? It works for me. Just consider that tikz automatically clips the bouding box, so you need to add something on (0,0) otherwise the drawing will get clipped and it will look like the curve wasn't shifted, when it actually was... Try putting \path (0,0); somewhere inside the picture. – Guilherme Zanotelli Jan 19 '17 at 17:51
• Sorry, the answer you posted works well. However it doesn't seem to work if you previously define coordinates for the curve (see my edit) – miga89 Jan 19 '17 at 18:20

Coordinates are not shifted, they are fixed (which is a good thing, normally that's what we want). You can do this in two ways: transform canvas={shift={(2cm,1cm)}} instead of just shift.

Or you can shift all coordinates: c/.style={shift={(2cm,1cm)}} then:

\draw[shift={(2cm,1cm)}] ([c]A1) .. controls ([c]A2) and ([c]A3) .. ([c]A4);


Both should work and the second way should be prefferd, messing with coordinate system transformations can lead to unexpected result (unexpected if you don't know what the tool does...).

Another idea (which could or could not be appropiate to your case, I don't know) is to define the required shape as a pic. Inside the pic you can use named coordinates to draw your shape, and then, when the pic is used as part of your drawing it can be easily shifted, scaled or rotated:

\documentclass[11pt]{standalone}
\usepackage{tikz}
%\usepackage{pgfplots}

\tikzset{
mybezier/.pic = {
\coordinate (A1) at (0,0);
\coordinate (A2) at (1,1);
\coordinate (A3) at (2,-1);
\coordinate (A4) at (3,0);
\draw (A1) .. controls (A2) and (A3) .. (A4);
}
}
\begin{document}
\begin{tikzpicture}
\path (0,0) pic {mybezier};
\path (2,1) pic {mybezier};
\path (0,-1) pic[red, rotate=-30, scale=1.5] {mybezier};
\end{tikzpicture}
\end{document}


Produces: