以下代码渲染了五个圆,每个圆与一个或两个其他圆相交,以及一条线段PQ
。线段PQ
与每个圆相交两次。如何将线段 和 处的交点标记为 ,将circle_1
另一个(0,-r)
交点PQ_1
标记circle_1
为?如何将“接近”PQ_2
的线段 和 的交点标记为,将“接近”的线段 和 的交点标记为?circle_2
PQ_2
PQ_3
circle_3
PQ_3
PQ_4
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\begin{document}
\begin{tikzpicture}[x=0.25cm, y=0.25cm]
\draw[blue, name path=circle_1] let \n1={sqrt(18/pi)} in (0,0) circle (\n1);
\draw[blue, name path=circle_2] let \n1={sqrt(18/pi)} in (3.40851,0) circle (\n1);
\draw[blue, name path=circle_3] let \n1={sqrt(18/pi)} in ({2*3.40851},0) circle (\n1);
\draw[blue, name path=circle_4] let \n1={sqrt(18/pi)} in ({3*3.40851},0) circle (\n1);
\draw[blue, name path=circle_5] let \n1={sqrt(18/pi)} in ({4*3.40851},0) circle (\n1);
\path let \n1={sqrt(18/pi)} in coordinate (P) at (0,-\n1);
\path let \n1={sqrt(18/pi)}, \n2={sqrt(18/pi)} in coordinate (Q) at ({4*3.40851},\n2);
\draw[name path=PQ] (P) -- (Q);
\coordinate[name intersections={of=PQ and circle_1, by=PQ_1}];
\coordinate[name intersections={of=PQ and circle_2, by=PQ_2}];
\coordinate[name intersections={of=PQ and circle_3, by=PQ_3}];
\coordinate[name intersections={of=PQ and circle_2, by=PQ_4}];
\coordinate[name intersections={of=PQ and circle_4, by=PQ_5}];
\coordinate[name intersections={of=PQ and circle_3, by=PQ_6}];
\coordinate[name intersections={of=PQ and circle_5, by=PQ_5}];
\coordinate[name intersections={of=PQ and circle_4, by=PQ_6}];
\draw[fill=green] (PQ_5) circle (1.5pt);
\end{tikzpicture}
\end{document}
答案1
\documentclass[tikz]{standalone}
\usetikzlibrary{calc,intersections}
\begin{document}
\begin{tikzpicture}[x=0.25cm, y=0.25cm]
\draw[blue, name path=circle_1] let \n1={sqrt(18/pi)} in (0,0) circle (\n1);
\draw[blue, name path=circle_2] let \n1={sqrt(18/pi)} in (3.40851,0) circle (\n1);
\draw[blue, name path=circle_3] let \n1={sqrt(18/pi)} in ({2*3.40851},0) circle (\n1);
\draw[blue, name path=circle_4] let \n1={sqrt(18/pi)} in ({3*3.40851},0) circle (\n1);
\draw[blue, name path=circle_5] let \n1={sqrt(18/pi)} in ({4*3.40851},0) circle (\n1);
\path let \n1={sqrt(18/pi)} in coordinate (P) at (0,-\n1);
\path let \n1={sqrt(18/pi)}, \n2={sqrt(18/pi)} in coordinate (Q) at ({4*3.40851},\n2);
\draw[name path=PQ] (P) -- (Q);
\coordinate[name intersections={of=PQ and circle_1, by={PQ_1, PQ_2}}];
\coordinate[name intersections={of=PQ and circle_2, by={PQ_3, PQ_5}}];
\coordinate[name intersections={of=PQ and circle_3, by={PQ_7, PQ_4}}];
\coordinate[name intersections={of=PQ and circle_4, by={PQ_8, PQ_6}}];
\coordinate[name intersections={of=PQ and circle_5, by={PQ_10,PQ_9}}];
\foreach \i in {1,...,10}
\draw (PQ_\i) circle (1pt) node[below,font=\tiny] {\i};
\end{tikzpicture}
\end{document}
答案2
比下面的解决方案更短更简单的解决方案。(请注意,我用 画直线to[bend left=0]
。为什么?参见这里。
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[x=0.25cm, y=0.25cm]
\draw[blue, name path=circles] foreach \X in {0,...,4}
{({\X*3.40851},0) circle [radius={sqrt(18/pi)}]};
\draw[name path=PQ] (0,{-sqrt(18/pi)}) coordinate (P)
to[bend left=0] ({4*3.40851},{sqrt(18/pi)}) coordinate (Q);
\path[name intersections={of=PQ and circles,sort by=PQ,name=PQ,total=\t}]
foreach \X in {1,...,\t}
{node[above] at (PQ-\X) {\X}};
\end{tikzpicture}
\end{document}
或者(使用sort by
)
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\begin{document}
\begin{tikzpicture}[x=0.25cm, y=0.25cm]
\draw[blue, name path=circle_1] let \n1={sqrt(18/pi)} in (0,0) circle (\n1);
\draw[blue, name path=circle_2] let \n1={sqrt(18/pi)} in (3.40851,0) circle (\n1);
\draw[blue, name path=circle_3] let \n1={sqrt(18/pi)} in ({2*3.40851},0) circle (\n1);
\draw[blue, name path=circle_4] let \n1={sqrt(18/pi)} in ({3*3.40851},0) circle (\n1);
\draw[blue, name path=circle_5] let \n1={sqrt(18/pi)} in ({4*3.40851},0) circle (\n1);
\path let \n1={sqrt(18/pi)} in coordinate (P) at (0,-\n1);
\path let \n1={sqrt(18/pi)}, \n2={sqrt(18/pi)} in coordinate (Q) at ({4*3.40851},\n2);
\draw[name path=PQ] (P) -- (Q);
\coordinate[name intersections={of=PQ and circle_1, by=PQ_1}];
\coordinate[name intersections={of=PQ and circle_2, by=PQ_2}];
\coordinate[name intersections={of=PQ and circle_3,sort by=circle_3, by={dummy,PQ_3}}];
\coordinate[name intersections={of=PQ and circle_4,sort by=circle_4, by={PQ_5,PQ_4}}];
\coordinate[name intersections={of=PQ and circle_5,sort by=circle_5, by={PQ_6,PQ_5}}];
\foreach \X in {1,...,6}
{\node[above] at (PQ_\X) {\X};}
\draw[fill=green] (PQ_5) circle (1.5pt);
\end{tikzpicture}
\end{document}