我希望沿着曲线绘制间隔开的点,并为每个点分配一个唯一的坐标,以便该坐标可用作箭头的端点等。从这个帖子,以下代码绘制了一条等间距点的曲线没有指定坐标:
\usetikzlibrary{hobby}
\usetikzlibrary{decorations.markings}
\tikzset{equally spaced dots/.style={postaction={decorate,
decoration={markings,% switch on markings
mark=% actually add a mark
between positions 0 and 1 step 0.9999/#1
with
{
\fill circle (1pt);
}
}}}}
\begin{document}
\begin{tikzpicture}
\draw[equally spaced dots=5] (0,0) (0,0) to[curve through={(6,4) .. (4,9) .. (1,7)}]
(3 ,5);
\end{tikzpicture}
\end{document}
我的问题是 - 我该如何为每个点分配一个坐标?例如,第 i 个点应该有坐标c-i
(这样最后我就有了坐标c-1
, c-2
, ...,c-6
可以用来处理上面的例子)。
答案1
\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}
我想,您正在寻找。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{hobby}
\usetikzlibrary{decorations.markings}
\tikzset{equally spaced dots/.style={postaction={decorate,
decoration={markings,% switch on markings
mark=% actually add a mark
between positions 0 and 1 step 0.9999/#1
with
{
\node[circle,fill,inner sep=1pt](c-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}){};
}
}}}}
\begin{document}
\begin{tikzpicture}
\draw[equally spaced dots=5] (0,0) (0,0) to[curve through={(6,4) .. (4,9) .. (1,7)}]
(3 ,5);
\draw[red] (c-2) -- (c-4);
\end{tikzpicture}
\end{document}
红线是为了表明它有效。