# tikz array of coordinates: iteration and addressing elements

Given the following array of coordinates

 \def\points{ (-1, 3) (2, 7) (3, 8) }


(see its use e.g. in TikZ: Smooth curve through three points without changing direction)

how do I

1. iterate (in tikz) over the coordinates? e.g.

"iterate over coordinates"
{
How to get the coordinate the iterator is pointing to?
How to get the iteration index?
}

2. address an element directly, e.g. coordinate 2 (i.e. (2, 7)) e.g.

\coordinate (A) at ("second coordinate at \points");


A similar question regarding 2D matrices in tikz is posed at 2D tikz matrices: iteration and addressing elements

• Please provide a complete minimal example people can compile. What is the problem iterating over the coordinates? This usually works out-of-the-box, so it isn't clear what the problem might be as you don't say. You can retrieve the x/y part using the lower level PGF stuff. There's a question about this somewhere. – cfr Dec 2 '17 at 21:41
• I'd probably use \foreach \x/\y in {-1/3, 2/7, 3/8} {...} but, as cfr says, without a minimal working example it's tricky to say whether this is the best approach for you. – Andrew Dec 3 '17 at 11:25
• expanded my questions – Viesturs Dec 3 '17 at 12:09
• I think you have been asking XY questions where you want X but asking about Y's. How do you want to use these points? – percusse Dec 3 '17 at 12:32
• @Viesturs Then your question is answered in your previous questions. Just make an array and access them as specified by egreg's answer. – percusse Dec 3 '17 at 13:02

For the first one, there is a simple solution. The second one is not so easy. You just have to iterate and print when you hit the index.

\documentclass{article}
\usepackage{tikz}
\begin{document}

\def\points{(-1,3), (2,7), (3,8)}

\begin{tikzpicture}
\foreach \p in \points {
\node at \p {\p};
}

\foreach \p [count=\i] in \points {
\ifnum\i=2
\node at \p {Hello};
\fi
}
\end{tikzpicture}

\end{document}