tikzでベジェ曲線全体をシフトする

tikzでベジェ曲線全体をシフトする

制御点を変更せずに、ベジェ曲線全体を、たとえば x 方向に 2 cm、y 方向に 1 cm シフトする簡単な方法はありますか?

\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キーは、その用途には使えないようです。ありがとうございます

編集:ギレルメが指摘したように、シフトプロパティはうまく機能します:

\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}

すると、2 番目の曲線は元の位置から移動しなくなります。

答え1

座標はシフトされず、固定されます (これは良いことであり、通常はそれが望ましいことです)。これを行うtransform canvas={shift={(2cm,1cm)}}には、 という 2 つの方法がありますshift

または、すべての座標をシフトすることもできますc/.style={shift={(2cm,1cm)}}

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

どちらも機能するはずですが、2 番目の方法が推奨されます。座標系の変換をいじると、予期しない結果が発生する可能性があります (ツールの動作がわからない場合は予期しない結果になります)。

答え2

もう 1 つのアイデア (あなたのケースに適するかどうかはわかりません) は、必要なシェイプを として定義することです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}

生産:

結果

関連情報