4

I am wanting to draw five semi-circles in a row (something like the second photo). This is a graph with the dots as vertices/nodes. I can draw one semi-circle, which is centered at the origin (pleae see first photo) and this is exactly what I want them to look like, but I can't duplicate it at centres (-6;0), (-12;0), (6;0) and (12;0). How do I draw the other 4?

I attach my LateX code.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,decorations.pathmorphing,backgrounds,positioning,fit,petri,calc,graphs,graphs.standard}

\begin{document}

 \begin{figure}[h]
    \begin{center}
        \begin{tikzpicture}
            [scale=0.6,inner sep=0.5mm, % this is the node radius
            vertex/.style={circle,draw}, % this defines the default style for the vertex class
            thickedge/.style={line width=2pt}] % this defines the default style for the thick edges

            \def\r{3} 

            \foreach \point in {(0:\r) ,(90:\r),(180:\r),(60:\r),(30:\r),(150:\r),(120:\r)} 
            \draw[fill=white] \point circle(.12);
            \node at (60:\r) {} ;
            \node at (30:\r) {} ;
            \node at (150:\r) {} ;
            \node at (120:\r) {} ;


            \node[vertex] (1) at (0,0) [fill=white] {};
            \node[vertex] (2) at (0,3) [fill=white] {};
            \node[vertex] (3) at (-3,0) [fill=white] {};
            \node[vertex] (5) at (3,0) [fill=white] {};

            \draw (1)--(2);
            \draw (3)--(1)--(5);

            \draw (0,0)+(122:3cm) arc[start angle=122, end angle=148, radius=3cm];
            \draw (0,0)+(32:3cm) arc[start angle=32, end angle=58, radius=3cm];
            \draw (0,0)+(28:3cm) arc[start angle=28, end angle=2, radius=3cm];
            \draw (0,0)+(-182:3cm) arc[start angle=-182, end angle=-208, radius=3cm];
            \draw  (0,0)+(-242:3cm) arc[start angle=-242, end angle=-268, radius=3cm];
            \draw  (0,0)+(-272:3cm) arc[start angle=-272, end angle=-298, radius=3cm];
        \end{tikzpicture}
    \end{center}
\end{figure}

\end{document}

LateX output

5 semi-circles in a row

MS-SPO
  • 11,519
Emily
  • 125
  • 6

2 Answers2

6

Welcome to TeX.SE

I think you're looking for something like this, using a couple of \foreach loops to repeat semicircles and points:

\documentclass[tikz,border=1.618]{standalone}

\begin{document} \begin{tikzpicture} \foreach\i in {0,2,...,8} { \draw (\i,0) arc (180:0:1) -- cycle; \foreach\j in {0,30,60,...,180} \fill (\i+1,0) ++ (\j:1) circle (1pt); \draw (\i+1,0) --++ (0,1); \fill (\i+1,0) circle (1pt); } \end{tikzpicture} \end{document}

enter image description here

Update (white nodes): In this case we need to draw the lines before the nodes:

\documentclass[tikz,border=1.618]{standalone}

\begin{document} \begin{tikzpicture} \foreach\i in {0,2,...,8} { \draw (\i,0) arc (180:0:1) -- cycle; \draw (\i+1,0) --++ (0,1); % <-- before the nodes \foreach\j in {0,30,60,...,180} \draw[black,fill=white] (\i+1,0) ++ (\j:1) circle (1pt); \draw[black,fill=white] (\i+1,0) circle (1pt); } \end{tikzpicture} \end{document}

enter image description here

Juan Castaño
  • 28,426
  • 1
    Amazing, thank you so much, Juan! This is incredible! – Emily May 11 '23 at 08:57
  • @EmilyJaneRivett-Carnac, you're welcome!! – Juan Castaño May 11 '23 at 11:05
  • Counter proposal, use pic to draw it in a more compact fashion. is it worth me posting an answer? like this one https://tex.stackexchange.com/questions/684611/tikz-how-to-fill-a-part-of-shape-with-a-color/684652#684652 – anis May 11 '23 at 13:55
  • @anis, I don't know what you have in mind. I'm a \pic enthusiast, but here we don't need the capabilities of a \pic, it's enough with a loop because all semicircles are identical (IMHO). That said, a \pic could make the semicircle more customizable: sizes, rotations, colors,.. So if your idea is to expand the OP figure, go ahead, by any means – Juan Castaño May 11 '23 at 19:05
  • I have posted the pic approach from your MWE. what further fun can we have with? – anis May 12 '23 at 07:36
2

Just for fun let's do it with pic. more details about pic are here. The short version is that it is a tikz code fragment that you can predefine and reuse really easily. as Juan Castaño said : "That said, a \pic could make the semicircle more customizable: sizes, rotations, colors,". You can more by doing less. Here is the code:

\documentclass[border=1.618]{standalone}
\usepackage{tikz}

\begin{document} \begin{tikzpicture}[ semicircles/.pic={ \draw (0,0) arc (180:0:#1) -- cycle; \foreach\j in {0,30,60,...,180} \fill (#1,0) ++ (\j:#1) circle (1pt); \draw (#1,0) --++ (0,#1); \fill (#1,0) circle (1pt); }
] \foreach \j in {0,2,...,8}{ \pic at (\j,0){semicircles=1}; \pic [rotate=45,yshift=5cm] at (\j,0){semicircles=2}; } \end{tikzpicture} \end{document}

Here is the result.

enter image description here

Edit: With Juan Castaño's suggestion, we can add a pic actions which are style option that can only be deployed in a pic.

The usefulness stems from the ability of adding arbitrary style and let's us transmit <key>=<value> argument to change the style of some content of the pic.

from the last code, all that we change is

\fill (#1,0) circle (1pt);

into

\fill [pic actions] (#1,0) circle (1pt);

Which means that now any call to this pic can change the circle's style like this:

``

\begin{tikzpicture}[
     semicircles/.pic={ 
        \draw (0,0) arc (180:0:#1) -- cycle;
        \foreach\j in {0,30,60,...,180}
            \fill (#1,0) ++  (\j:#1) circle (1pt);
        \draw (#1,0) --++ (0,#1);
        \fill [pic actions] (#1,0) circle (1pt);
        }   
    ]
    \foreach \j in {0,2,...,8}{
        \pic  at (\j,0){semicircles=1};
        \pic  [rotate=45,yshift=5cm] at (\j,0){semicircles=2};
        \pic [fill=red] at (\j,-2){semicircles=1};
    }
\end{tikzpicture}

enter image description here

anis
  • 1,510
  • 5
  • 13
  • 1
    Very good (+1)!!! As you're asking, perhaps you can use pic actions and add the capability to chose the dot filling colour (it was an OP request). – Juan Castaño May 12 '23 at 07:55
  • 1
    @JuanCastaño i think a useful one would be the ability to generate this pattern with a single line as a path and be able to bend it, flip it. It would be instantiated like a chain. – anis May 12 '23 at 08:18
  • Probably, but in doesn't look very simple – Juan Castaño May 12 '23 at 08:21
  • 2
    Thank you so so much @JuanCastaño and @anis! You have helped me tremendously! I really appreciate your time and assistance. – Emily May 15 '23 at 12:15