0

I wish to draw spaced dots along a curve, and assign a unique coordinate to each one such that the coordinate may be used as endpoints for arrows, etc. From this post, the following code draws a curve with equally spaced points which do not have coordinates assigned to them:

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

enter image description here

My question is - how do I assign a coordinate to each one? For example, the i-th point should have the coordinate c-i (such that at the end I have coordinates c-1, c-2, ..., c-6 to work with for the above example).

1 Answers1

2

You are looking for \pgfkeysvalueof{/pgf/decoration/mark info/sequence number}, I think.

enter image description here

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

enter image description here

The red line is to show that it works.