# Labeling distinct points of a line and circle using “intersections package”

The following code renders five circles, each circle intersecting one or two other circles, and a line segment PQ. Line segment PQ intersects each circle twice. How do I label the intersection of the line segment and circle_1 at (0,-r) to be PQ_1 and the other intersection with circle_1 to be PQ_2? How do I label the intersection of the line segment and circle_2 that is "close to PQ_2" to be PQ_3, and the intersection of the line segment and circle_3 that is "close to PQ_3" to be 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}


\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} • I appreciate you putting the intersections in order for me. – A gal named Desire May 9 at 20:38
• How would I draw a blue arc from PQ_1 to PQ_2 going clockwise, a yellow arc from PQ_1 to PQ_2 going counterclockwise, a blue arc from PQ_3 to PQ_5 going clockwise, and a yellow arc from PQ_3 to PQ_5 going counterclockwise? – A gal named Desire May 9 at 20:47
• @AgalnamedDesire I don't understand what you mean. – user156344 May 9 at 20:54
• I want the circles to be drawn in two colors. The arcs of the circles above line segment PQ are to be drawn blue, and the arcs of the circles below PQ are to be drawn yellow. – A gal named Desire May 9 at 21:02

A much shorter and simpler solution than the one below. (Note that I draw the straight line with to[bend left=0]. Why? See here.)

\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}
\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} Or (using 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} • @marmot Yes, I think that this is what I wanted. I think that I had by=PQ_5, PQ_4 instead of by={PQ_5, PQ_4}. – A gal named Desire May 9 at 18:49
• @JouleV I agree, see my update. ;-) – user121799 May 9 at 18:54
• @JouleV What do you expect, hibernation just ended. ;-) – user121799 May 9 at 18:57
• @AgalnamedDesire \draw[red] let \p1=($(PQ_1)-({0*3.40851},0)$),\p2=($(PQ_3)-({0*3.40851},0)$),\n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)},\n3={veclen(\x1,\y1)} in ($({0*3.40851},0)+(\n1:\n3)$) arc(\n1:\n2:\n3); \draw[yellow] let \p1=($(PQ_1)-({0*3.40851},0)$),\p2=($(PQ_3)-({0*3.40851},0)$),\n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)},\n3={veclen(\x1,\y1)} in ($({0*3.40851},0)+(\n1:\n3)$) arc(\n1:\n2-360:\n3); – user121799 May 9 at 21:57
• \draw[red] let \p1=($(PQ_3)-({1*3.40851},0)$),\p2=($(PQ_5)-({1*3.40851},0)$),\n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)},\n3={veclen(\x1,\y1)} in ($({1*3.40851},0)+(\n1:\n3)$) arc(\n1:\n2:\n3); \draw[yellow] let \p1=($(PQ_3)-({1*3.40851},0)$),\p2=($(PQ_5)-({1*3.40851},0)$),\n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)},\n3={veclen(\x1,\y1)} in ($({1*3.40851},0)+(\n1:\n3)$) arc(\n1:\n2-360:\n3); – user121799 May 9 at 21:57