![如何在不绘制路径的情况下在两个路径的交点处定义 TikZ 坐标?](https://linux22.com/image/460824/%E5%A6%82%E4%BD%95%E5%9C%A8%E4%B8%8D%E7%BB%98%E5%88%B6%E8%B7%AF%E5%BE%84%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%E5%9C%A8%E4%B8%A4%E4%B8%AA%E8%B7%AF%E5%BE%84%E7%9A%84%E4%BA%A4%E7%82%B9%E5%A4%84%E5%AE%9A%E4%B9%89%20TikZ%20%E5%9D%90%E6%A0%87%EF%BC%9F.png)
是否可以在 TikZ 图片中将坐标定义为两条线的交点,或者更一般地说是两条路径的交点,而无需绘制线条(路径)?
例如,考虑以下 LaTeX 代码。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (p) at (.5,0);
\fill (p) circle (1pt);
\node [anchor=north] at (p) {P};
\draw (-1,0) -- ++(60:3);
\draw (1,0) -- ++(120:3);
\end{tikzpicture}
\end{document}
产生下面的图形。
我想在两条线段的交点处定义一个坐标以供以后使用,例如用于绘制与点 P 以及两条线段的交点重合的线,但不绘制线段。
如何才能做到这一点?
尝试解决方案
我尝试了以下操作:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\coordinate (p) at (.5,0);
\fill (p) circle (1pt);
\node [anchor=north] at (p) {P};
\path [name path=left] (-1,0) -- ++(60:3);
\path [name path=right] (1,0) -- ++(120:3);
\coordinate[name intersections={of=left and right}] (q) at (intersection-1);
\draw (p) -- (q);
\end{tikzpicture}
\end{document}
然而,这在 Overleaf 中产生了以下错误(使用 2022 LuaLatex 引擎):
! Package pgf Error: No shape named `intersection-1' is known.
See the pgf package documentation for explanation.
Type H <return> for immediate help.
...
l.13 ...{of=left and right}] (q) at (intersection-1)
;
答案1
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\coordinate (p) at (.5,0);
\fill (p) circle (1pt);
\node [anchor=north] at (p) {P};
\path[name path=line 1] (-1,0) -- ++(60:3);
\path[name path=line 2] (1,0) -- ++(120:3);
\path [name intersections={of=line 1 and line 2,by=K}];
\draw (K) -- (p);
\end{tikzpicture}
\end{document}
path
下面,左侧为相同的绘图,draw
右侧为: