0

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}

2 Answers2

2
\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}

enter image description here

  • I appreciate you putting the intersections in order for me. – A gal named Desire May 09 '19 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 09 '19 at 20:47
  • @AgalnamedDesire I don't understand what you mean. –  May 09 '19 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 09 '19 at 21:02
1

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} 
   {({\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}

enter image description here

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}

enter image description here

  • 1
    @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 09 '19 at 18:49
  • @JouleV I agree, see my update. ;-) –  May 09 '19 at 18:54
  • @marmot You did not type your comment fast enough ;) –  May 09 '19 at 18:55
  • 1
    @JouleV What do you expect, hibernation just ended. ;-) –  May 09 '19 at 18:57
  • 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 09 '19 at 20:48
  • @AgalnamedDesire Which version are you talking about? In the first code you may use \path[name intersections={of=PQ and circles,sort by=PQ,name=PQ,total=\t}] \pgfextra{\xdef\NumInt{\t}} foreach \X in {1,...,\t} {node[above] at (PQ-\X) {\X}}; \foreach \X [evaluate=\X as \NextX using {int(\X+1)}]in {1,...,\numexpr\NumInt-1} { \ifodd\X \draw[blue] (PQ-\X) to[bend left] (PQ-\NextX); \else \draw[yellow] (PQ-\X) to[bend right] (PQ-\NextX); \fi }. –  May 09 '19 at 21:12
  • These commands in your \foreach command are not familiar to me. Please give me the commands individually for circle_1 and circle_2. – A gal named Desire May 09 '19 at 21:19
  • @AgalnamedDesire I still do not know which of the two codes you are referring to. –  May 09 '19 at 21:30
  • Use the following three commands. – A gal named Desire May 09 '19 at 21:43
  • \coordinate[name intersections={of=PQ and circle_1, by={PQ_1, PQ_2}}]; – A gal named Desire May 09 '19 at 21:44
  • \coordinate[name intersections={of=PQ and circle_2, by={PQ_3, PQ_5}}]; – A gal named Desire May 09 '19 at 21:45
  • \coordinate[name intersections={of=PQ and circle_3, by={PQ_7, PQ_4}}]; – A gal named Desire May 09 '19 at 21:45
  • 1
    @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); –  May 09 '19 at 21:57
  • 1
    \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); –  May 09 '19 at 21:57
  • @AgalnamedDesire But this is IMHO a so-called xy problem because what you really seem to be looking for is the intersection segments that can be drawn with the pgfplots (!) library fillbetween. –  May 09 '19 at 21:58
  • What is "atan2(\y1,\x1)"? I have only used "atan(\y1/\x1)". – A gal named Desire May 10 '19 at 18:27
  • Why is the command ... – A gal named Desire May 10 '19 at 18:27
  • \path[fill=red!25] let \p1=($(PQ_6)-(3*3.40851,0)$), \p2=($(PQ_8)-(3*3.40851,0)$), \n1={atan2(\y1,\x1)}, \n2={atan2(\y2,\x2)}, \n3={veclen(\x1,\y1)} in ($(3*3.40851,0) +(\n1:\n3)$) arc (\n1:\n2-360:\n3); – A gal named Desire May 10 '19 at 18:28
  • ... coloring the fourth circle pink instead of only that part of the fourth circle below line segment PQ? – A gal named Desire May 10 '19 at 18:28
  • @AgalnamedDesire atan2 also puts you in the right quadrant. That is, if \y1 and \x1 are both negative, the sign will cancel in the quotient, i.e. in atan, but not in atan2. Other than that I feel that this post is now at a stage where no one else will benefit any more from the discussion. If you have a clear question others may benefit from too, please ask a new question. I get now some information scattered over several comments and find it impossible to extract the relevant information, so I stop here. –  May 10 '19 at 18:33
  • I get an error if I replace atan2 with atan in this code. I have used atan in hundreds of other TikZ environments. I will post another question about this code later. – A gal named Desire May 10 '19 at 18:38