Tikz:两个不同点的交点

Tikz:两个不同点的交点

使用 Tikz,如果我们想绘制这个:

在此处输入图片描述

我们可以使用

(...)
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
    \begin{tikzpicture}
    \coordinate (A) at (0,3);
    \coordinate (B) at (2,0);
    \coordinate (C) at (-3,0);
    \coordinate (D) at (0,-1);
    \draw [name path=A--D] (A)--(D);
    \draw [name path=C--B] (C) -- (B);
    \path [name intersections={of=A--D and C--B, by=P}];
    \node at (P)[below left]{P};
    \end{tikzpicture}
\end{document}

但如果我们想做类似的事情

在此处输入图片描述

或者

在此处输入图片描述

有没有办法使用交叉点库?

顺便说一下,我使用的例子

(...)
\usepackage{tikz}
\usetikzlibrary{through}
\begin{document}
    \begin{tikzpicture}[line width=0.9pt]
    \coordinate (A) at (1,0);
    \coordinate (B) at (-1.5,0);
    \node [draw] at (A) [circle through={(B)}]{};
    \node [draw] at (B) [circle through={(A)}]{};
    \end{tikzpicture}
\end{document}

(...)
\usepackage{tikz}
\usetikzlibrary{through}
\begin{document}
    \begin{tikzpicture}[line width=0.9pt]
    \coordinate (A) at (-2,0);
    \coordinate (B) at (3,0);
    \coordinate (C) at (0, 1);
    \coordinate (D) at (-1,0);
    \draw (A) -- (B);
    \node [draw] at (C) [circle through={(D)}] {};
    \end{tikzpicture}
\end{document}

然后手动添加节点A和B。

答案1

使用节点边界路径进行交叉。以下是您的示例,以及计算并用红点标记的交叉点。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{intersections,through}
\begin{document}
\begin{tikzpicture}[line width=0.9pt]
    \coordinate (A) at (1,0);
    \coordinate (B) at (-1.5,0);
    \node [draw,name path=A] at (A) [circle through={(B)}]{};
    \node [draw,name path=B] at (B) [circle through={(A)}]{};
    \path[name intersections={of=A and B,name=i,total=\t}]
     foreach \X in {1,...,\t}{(i-\X) node[red,circle,fill,inner sep=2pt]{}};
\end{tikzpicture}
%
\begin{tikzpicture}[line width=0.9pt]
    \coordinate (A) at (-2,0);
    \coordinate (B) at (3,0);
    \coordinate (C) at (0, 1);
    \coordinate (D) at (-1,0);
    \draw[name path={A--B}] (A) -- (B);
    \node [draw,name path=C] at (C) [circle through={(D)}] {};
    \path[name intersections={of=A--B and C,name=i,total=\t}]
     foreach \X in {1,...,\t}{(i-\X) node[red,circle,fill,inner sep=2pt]{}};
\end{tikzpicture}   
\end{document}

在此处输入图片描述

当然你也可以使用标签。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{intersections,through}
\begin{document}
\begin{tikzpicture}[line width=0.9pt]
    \coordinate (A) at (1,0);
    \coordinate (B) at (-1.5,0);
    \node [draw,name path=A] at (A) [circle through={(B)}]{};
    \node [draw,name path=B] at (B) [circle through={(A)}]{};
    \path[name intersections={of=A and B,by={i-A,i-B}}]
     foreach \X [count=\Y from 0]in {A,B}{(i-\X) node[anchor=-90+180*\Y]{$\X$}};
\end{tikzpicture}
%
\begin{tikzpicture}[line width=0.9pt]
    \coordinate (A) at (-2,0);
    \coordinate (B) at (3,0);
    \coordinate (C) at (0, 1);
    \coordinate (D) at (-1,0);
    \draw[name path={A--B}] (A) -- (B);
    \node [draw,name path=C] at (C) [circle through={(D)}] {};
    \path[name intersections={of=A--B and C,by={i-A,i-B}}]
      foreach \X in {A,B}{(i-\X) node[below]{$\X$}};
\end{tikzpicture}   
\end{document}

在此处输入图片描述

相关内容