Tikz 线与未命名点的交点?

Tikz 线与未命名点的交点?

这有效:

\draw (0,0) coordinate (A);
\draw (1,1) coordinate (B);
\draw (1,0) coordinate (C);
\draw (0,1) coordinate (D);
\coordinate (X) at (intersection of A--B and C--D);

但这不行:

\draw (0,0) coordinate (A);
\draw (1,1) coordinate (B);
\coordinate (X) at (intersection of A--B and (0,1)--(1,0));

我认为使用点会非常方便,就像在第二个例子中那样,在将它们用作线的端点之前不需要命名。

有没有什么方法可以强制 TiKZ 创建由端点给出的线的交点,而无需先命名这些端点?

答案1

有了intersections图书馆,你不需要命名每一个coordinate,而是每一个path

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}

\begin{tikzpicture}
\draw (0,0) coordinate (A);
\draw (1,1) coordinate (B);
\draw (1,0) coordinate (C);
\draw (0,1) coordinate (D);
\draw (A)--(B);\draw (C)--(D);  % added for `cross symbol` demonstration
\coordinate (X) at (intersection of A--B and C--D);

%

\begin{scope}[xshift=2cm]    % so that they won't overlap
\draw[name path=AB] (0,0)  -- (1,1);
\draw[name path=CD] (0,1) -- (1,0);
\draw [name intersections={of=AB and CD, by=x}] (x) circle (2pt)node[right] {$x$};
\end{scope}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

这是一次尝试,将(...)(1,0)--(0,1) 中的 替换为{...}

在此处输入图片描述

代码

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\draw (0,0) coordinate (A);
\draw (1,1) coordinate (B);
\draw (1,0) coordinate (C);
\draw (0,1) coordinate (D);
\draw (A)--(B);\draw (C)--(D);  % added for `cross symbol` demonstration
\coordinate (X) at (intersection of A--B and C--D);

%

\begin{scope}[xshift=2cm]    % so that they won't overlap
\draw (0,0)  coordinate (A);
\draw (1,1)  coordinate (B);
%\draw (1,0) coordinate (C);
%\draw (0,1) coordinate (D);
\node (Y) at (intersection of A--B and {0,1}--{1,0}){Y}; % change coordinate to node for showing Y
\end{scope}
\end{tikzpicture}

\end{document}

相关内容