12

The following code fails:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\draw[help lines] (0,0) grid (10,10);
\draw[very thick,rotate around={45:(2.3,5)}] (2.3,5) rectangle ++(4,0.3) ++(0,-0.15) coordinate (p2);
\draw[name path=1st] (1.8,4)--(1.8,6);
\draw[name path=2nd] (p2)--+(225:5);
\coordinate[name intersections={of=1st and 2nd}] (i12) at (intersection-1);
\fill[red] (i12) circle (2pt);
\end{tikzpicture}
\end{document}

But if I substitute \node[name intersections={of=1st and 2nd}] (i12) at (intersection-1) {}; for \coordinate[name intersections={of=1st and 2nd}] (i12) at (intersection-1);, I get what I want:

Why does the first method fail? Thank you!

2
  • 1
    This doesn't answer your question, but you could also just do \path[name intersections={of=1st and 2nd,by={i12}}]; instead of using \node/\coordinate. Commented Apr 11, 2017 at 7:35
  • 1
    According to page 218 in pgfmanual, coordinate is a “light-weight” node. I suppose that this means that coordinate definition is limited compared with node. The solution proposed by Torbjørn T. is the one proposed in documentation, but if you insist in using your syntax to obtain a coordinate node, you could also use: \node[coordinate, name intersections={of=1st and 2nd}] (i12) at (intersection-1) {};
    – Ignasi
    Commented Apr 11, 2017 at 8:00

2 Answers 2

9

In essence, \coordinate is an alias for \node[shape=coordinate]. Looking through tikz.code.tex, it would appear that \coordinate[options] becomes \node[shape=coordinate,options] and so your \coordinate syntax ought to work. I'm not entirely sure why it doesn't (and my investigation time is a bit short today), but the following code does work, which I would say shows that the intention is that the original syntax should work and that that it doesn't might be considered a bug (though I'd investigate further to see exactly where it breaks down before filing it).

\documentclass[border=5mm]{standalone}
%\url{http://tex.stackexchange.com/q/364184/86}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\draw[help lines] (0,0) grid (10,10);
\draw[very thick,rotate around={45:(2.3,5)}] (2.3,5) rectangle ++(4,0.3) ++(0,-0.15) coordinate (p2);
\draw[name path=1st] (1.8,4)--(1.8,6);
\draw[name path=2nd] (p2)--+(225:5);
\coordinate[name intersections={of=1st and 2nd},name=i12,at=(intersection-1)]; 
\fill[red] (i12) circle (2pt);
\end{tikzpicture}
\end{document}

(A bit of cutting and pasting shows that it is the at part that causes the problem. Putting at=(intersection-1) as an option works, but at (intersection-1) afterwards doesn't.)


Update: I see the problem now. When you use the at (intersection-1) syntax then TikZ calculates the location of (intersection-1) at the point when it parses that option. This is, as @TeXnician says, a problem because intersection-1 has not yet been calculated. But when at=(intersection-1) is passed as an option, this is not calculated until much later in the process whereupon the path intersection has been calculated.

Nodes are different here because the processing for nodes is a bit different to that for coordinates. Essentially, the \coordinate is doing some pre-processing before shipping off its stuff to the \node. This is necessary, but does mean that things get processed in a slightly different order than for \nodes.

6

One version would be to use

\coordinate[name intersections={of=1st and 2nd,by=i12}];
\fill[red] (i12) circle (2pt);

which names the point using intersections. Another option is to use

\coordinate[name intersections={of=1st and 2nd}];
\fill[red] (intersection-1) circle (2pt);

or

\path[name intersections={of=1st and 2nd}];
\coordinate (i12) at (intersection-1);
\fill[red] (i12) circle (2pt);

which uses the internal name for the intersection.

Your code does not work, because the intersection is not known to TikZ at this stage, so it cannot assign the coordinate to the point.

3
  • 1
    But why does it work with \node instead of \coordinate? Commented Apr 11, 2017 at 7:36
  • @TorbjørnT. Only speculation, but probably because of the processing of optional arguments (I'm currently reading the TikZ manual searching for it).
    – TeXnician
    Commented Apr 11, 2017 at 7:46
  • I still can only guess (after reading the manual) that nodes preprocess optional arguments other than coordinates. But probably we should wait for someone who is able to really answer this.
    – TeXnician
    Commented Apr 11, 2017 at 9:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .