为什么在两条路径的交叉点处 `\coordinate` 会失败,而 `\node` 会成功?

为什么在两条路径的交叉点处 `\coordinate` 会失败,而 `\node` 会成功?

以下代码失败:

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

但如果我替换\node[name intersections={of=1st and 2nd}] (i12) at (intersection-1) {};\coordinate[name intersections={of=1st and 2nd}] (i12) at (intersection-1);我就会得到我想要的:

为什么第一种方法会失败?谢谢!

答案1

本质上,\coordinate是 的别名\node[shape=coordinate]。查看tikz.code.tex,似乎\coordinate[options]变成了\node[shape=coordinate,options],因此您的\coordinate语法應該工作。我不太清楚为什么它不工作(而且我今天的调查时间有点短),但下面的代码工作,我想说这表明其意图是原始语法应该工作并且它不能被视为错误(虽然我会在提交之前进一步调查以确切了解它在哪里发生故障)。

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

(经过一点剪切和粘贴,我们发现这是at导致问题的部分。将其at=(intersection-1)作为选项放置时有效,但at (intersection-1)之后无效。)


更新:我现在明白问题所在了。使用语法时,TikZ 会在解析该选项时at (intersection-1)计算位置。正如 @TeXnician 所说,这是一个问题,因为尚未计算。但是当作为选项传递时,直到计算路径交点的过程的后期才会计算。(intersection-1)intersection-1at=(intersection-1)

这里的节点有所不同,因为节点的处理与坐标的处理略有不同。本质上,\coordinate在将其内容运送到之前,会进行一些预处理\node。这是必要的,但确实意味着处理顺序与\nodes 略有不同。

答案2

一个版本是使用

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

使用 来命名点intersections。另一个选项是使用

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

或者

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

它使用交叉点的内部名称。

您的代码不起作用,因为 TikZ 在此阶段还不知道交点,所以无法将坐标分配给该点。

相关内容