TikZ - パスの先頭へのアクセス

TikZ - パスの先頭へのアクセス

TikZ では、次のように座標を指定してパスの末尾にアクセスできることがわかっています。

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{svg.path}

\begin{document}

\begin{tikzpicture}
\draw [green] svg {M201.1,673.2c1.4-39.8,2-52.2,18.2-70.8c11.7-13.5,18.3-24.3-7.7-49.4
        c-39.3-38-43.2-59.2,1-90.2c18.1-12.7,67.1-20.2,25.4-36.6c-18.2-7.2-23.5-9.7-26.9-39.2c-3-26.7-17.7-28.2-37.7-35
        c-20-6.9-87.7-28.8-50.2-78.2c23.5-31,58.6-73.9,83.1-118.2c13.3-24,22.4-56.5,38.6-85.9} coordinate (End);
\fill [red] (End) circle (4pt);
\end{tikzpicture}

\end{document}

同じ方法でパスの開始点にアクセスするにはどうすればいいでしょうか?

答え1

それは難しいですね!svg構文は TikZ パス構築メカニズムの多くをショートカットするため、明らかな解決策でcoordinate[pos=0] (Start)ある は機能しないようです。

したがって、このメソッドは、パスが構築されるとそれを取得し、初期座標を削除します。次に、そのポイントに TikZ 座標を作成します。

\documentclass{standalone}

%\url{http://tex.stackexchange.com/q/364315/86}
\usepackage{tikz}
\usetikzlibrary{svg.path}

\makeatletter

\def\tikz@startcoord#1#2#3#4\pgf@stop#5{%
\begingroup
\pgftransformreset
  \pgftransformshift{\pgfpoint{#2}{#3}}%
  \pgfnode{coordinate}{center}{}{#5}{}%
  \endgroup
  }

\tikzset{
  coordinate at start/.code={
    \tikz@addmode{%
      \pgfsyssoftpath@getcurrentpath\@temp
      \expandafter\tikz@startcoord\@temp\pgf@stop{#1}
    }%
  }
}
\makeatother

\begin{document}

\begin{tikzpicture}
\begin{scope}[xshift=1cm]
\draw [coordinate at start=Start,green,yshift=2cm] svg {M201.1,673.2c1.4-39.8,2-52.2,18.2-70.8c11.7-13.5,18.3-24.3-7.7-49.4
        c-39.3-38-43.2-59.2,1-90.2c18.1-12.7,67.1-20.2,25.4-36.6c-18.2-7.2-23.5-9.7-26.9-39.2c-3-26.7-17.7-28.2-37.7-35
        c-20-6.9-87.7-28.8-50.2-78.2c23.5-31,58.6-73.9,83.1-118.2c13.3-24,22.4-56.5,38.6-85.9} coordinate (End);
\end{scope}
\fill [red] (End) circle (4pt);
\fill [blue] (Start) circle (4pt);
\end{tikzpicture}

\end{document

}

これを行うにはもっと簡単な方法があるかもしれません...


現在の座標変換を無視するように更新されました (そうでない場合、座標変換は 2 回適用されます)。

答え2

おそらく OP の要件よりも少し粗雑ですが、SVG パスを分割することが許容できる場合は、最初の moveto の後に座標を置くと機能します。

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{svg.path}
\begin{document}
\begin{tikzpicture}
\draw [green, xshift=25] 
  svg {M201.1,673.2} 
  coordinate (Start)
  svg {c1.4-39.8,2-52.2,18.2-70.8c11.7-13.5,18.3-24.3-7.7-49.4
       c-39.3-38-43.2-59.2,1-90.2c18.1-12.7,67.1-20.2,25.4-36.6
       c-18.2-7.2-23.5-9.7-26.9-39.2c-3-26.7-17.7-28.2-37.7-35
       c-20-6.9-87.7-28.8-50.2-78.2c23.5-31,58.6-73.9,83.1-118.2
       c13.3-24,22.4-56.5,38.6-85.9}
  coordinate (End);
\fill [blue] (Start) circle [radius=.1];
\fill [red] (End) circle [radius=.1];
\end{tikzpicture}
\end{document}

関連情報