
有沒有簡單的方法可以在不改變控制點的情況下整體移動貝塞爾曲線,例如x方向移動2cm,y方向移動1cm?
\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}
xshift- 和 yshift-key 似乎無法用於此目的。謝謝
編輯:正如吉爾赫姆所指出的轉移屬性運作良好:
\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}
但是,當您預先定義曲線的座標時,它不起作用:
\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}
然後第二條曲線不會從其原始位置移動。
答案1
座標沒有移動,而是固定的(這是一件好事,通常這就是我們想要的)。您可以透過兩種方式執行此操作:transform canvas={shift={(2cm,1cm)}}
而不是僅僅shift
.
或者你可以移動所有座標:c/.style={shift={(2cm,1cm)}}
然後:
\draw[shift={(2cm,1cm)}] ([c]A1) .. controls ([c]A2) and ([c]A3) .. ([c]A4);
兩種方法都應該有效,並且應該首選第二種方法,弄亂坐標系轉換可能會導致意外結果(如果您不知道該工具的用途,則會出現意想不到的結果...)。
答案2
另一個想法(我不知道這可能或不適合您的情況)是將所需的形狀定義為pic
.在 內部,pic
您可以使用命名座標來繪製形狀,然後,當pic
用作繪圖的一部分時,可以輕鬆移動、縮放或旋轉:
\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}
生產: