如何向 TikZ 图片添加多个交点?

如何向 TikZ 图片添加多个交点?

下面的代码

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
 \foreach \a/\text in {0/,60/,120/,180/,240/,300/} 
    \draw[] (\a:1cm) circle (1.5cm) node[right] () {\text};
\end{tikzpicture}

\end{document}

生成 6 个圆,它们在 30 个点处相交。是否有可能在所有交点处放置点,而无需手动计算?

答案1

如果您所说的“无需手动计算”是指要避免分析计算,那么您可以使用该intersections库。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\newcounter{myintersection}
\begin{document}

\begin{tikzpicture}[int/.code={\stepcounter{myintersection}%
    \tikzset{name=i-\number\value{myintersection},circle,draw,inner sep=1pt}}]
 \foreach \a/\mytext [count=\X]in {0/,60/,120/,180/,240/,300/} 
    {\draw[name path=\X-path] (\a:1cm) circle[radius=1.5cm] node[right] {\mytext};
    \ifnum\X>1
     \foreach \Y in {1,...,\the\numexpr\X-1}
     {
     \path[name intersections={of=\X-path and
     \Y-path,total=\t}]
     foreach \Z in {1,...,\t}
      {(intersection-\Z) node[int]{}};}
    \fi
    }
\typeout{\number\value{myintersection} intersections found} 
\end{tikzpicture}
\end{document}

在此处输入图片描述

Z 也找到了 30 个交叉点,并将它们命名i-1i-30

附录:此版本用于检查交点数是否大于零。在上述情况下,这不是必需的,但在其他应用程序中则可能需要。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\newcounter{myintersection}
\begin{document}

\begin{tikzpicture}[int/.code={\stepcounter{myintersection}%
    \tikzset{name=i-\number\value{myintersection},circle,draw,inner sep=1pt}}]
 \foreach \a/\mytext [count=\X]in {0/,60/,120/,180/,240/,300/} 
    {\draw[name path=\X-path] (\a:1cm) circle[radius=1.5cm] node[right] {\mytext};
    \ifnum\X>1
     \foreach \Y in {1,...,\the\numexpr\X-1}
     {
     \path[name intersections={of=\X-path and
     \Y-path,total=\t}] \ifnum\t>0
     foreach \Z in {1,...,\t}
      {(intersection-\Z) node[int]{}}\fi;}
    \fi
    }
\end{tikzpicture}
\end{document}

相关内容