1

I am trying to draw a graph comprised of 13 triangles joined at the centre (i.e. a wheel graph with some edges missing from the outer cycle). I managed to connect the outer vertices to the central one but I would like to automate the insertion of the remaining edges. The vertices on the outer cycle are labelled from 1 to 26. For each odd vertex n, I want to draw an edge between this and vertex n+1, e.g. edges (1,2), (3,4), (5,6), etc. I tried the code below but I don't know how to "evaluate" the expression "\x + 1" to reference a vertex.

\begin{tikzpicture}[main/.style = {draw, circle, inner sep=1.2, fill=black}] 
\node[main, label=below:{$e$}] at (360:0mm) (0) {};
\graph[circular placement, group polar shift=(360/26:0), empty nodes, radius=6cm, nodes={circle, inner sep=1.2, draw=black, fill=black}] {
    \foreach \x in {1,...,26} {       
        \x -- (0);       
    };    
\foreach \x in {1,3,5,7,9,11,13,15,17,19,21,23,25} {
        \x -- \x + 1        
    };
};

\end{tikzpicture}

The result should look similar to the following but with all the missing edges on the outer cycle. enter image description here

Any help is very much appreciated!

3
  • 1
    how about draw 1 triangle, then rotate?
    – Black Mild
    Jul 11, 2021 at 1:57
  • You might try with \foreach \x/\y in{1/2,3/4,5/6,…}.
    – Bernard
    Jul 11, 2021 at 8:14
  • Thank you! it worked! : ) Jul 11, 2021 at 10:19

3 Answers 3

1

You want to evaluate \x+1.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs}

\begin{document}

\begin{tikzpicture}[
  main/.style = {draw, circle, inner sep=1.2, fill=black}
]
\node[main, label=below:{$e$}] at (360:0mm) (0) {};
\graph[
  circular placement,
  group polar shift=(360/26:0),
  empty nodes,
  radius=6cm,
  nodes={circle, inner sep=1.2, draw=black, fill=black}
]{
  \foreach \x in {1,...,26} {
    \x -- (0);
  };
  \foreach \x [evaluate=\x as \y using \x+1] in {1,3,...,25} {
    \x -- \y
  };
};
\end{tikzpicture}

\end{document}

enter image description here

However, the connections are not correctly placed. It might make more sense to draw one piece and rotate it.

1
  • thank you! yes, I see some of the connectors are slanted - weird.. Jul 11, 2021 at 10:14
0

May I suggest a simpler way to do that?

circular graph

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[dot/.style={circle,fill=black,inner sep=1.2pt}]
    \coordinate (0) at (0,0);
    \def\r{6}
    \foreach \i [evaluate=\i as \j using \i+1] in {1,3,...,25}
        \draw (0) -- (\i*360/26-360/52:\r) node[dot](\i){} -- (\j*360/26-360/52:\r) node[dot](\j){} -- cycle;
\end{tikzpicture}

\end{document}
4
  • That's great! Thank you! Jul 11, 2021 at 15:32
  • @AdrianLeverkuhn If this is what you needed, please consider upvoting and accepting this answer to let users know that you find your solution ;)
    – SebGlav
    Jul 11, 2021 at 16:00
  • unfortunately it does not let me upvote yet but I accepted the answer. Cheers Jul 11, 2021 at 16:04
  • Of course, because you're new here. Thanks anyway and feel free to come back with other questions.
    – SebGlav
    Jul 11, 2021 at 16:17
0

based on comments provided and other posts, I ended up with the following:

\begin{tikzpicture}[main/.style = {draw, circle, inner sep=1.2, fill=black}] 
\node[main, label=right:{$e$}] at (360:0mm) (0) {};
\graph[circular placement, group polar shift=(360/26:0), empty nodes, radius=4cm, nodes={circle, inner sep=1.2, draw=black, fill=black}] {
    \foreach \x in {1,...,26} {       
        \x -- (0);    
    };    
    \foreach \x [evaluate={\xi=int(\x+1);}] in {1, 3, ..., 25} {
        \foreach \y in {\x,...,\xi} {
            \x -- \y;
        };
    };
}; 

\foreach \x [count=\idx from 0] in {a, a^2, b, b^2, c, c^2, d, d^2, f, f^2, g, g^2, h, h^2, i, i^2, j, j^2, k, k^2, l, l^2, m, m^2, n, n^2} {     
    \pgfmathparse{90 + \idx * (360 / 26)} \node at (\pgfmathresult:4.4cm) {$\x$};   
}; 

\end{tikzpicture}

which produces this graph: enter image description here

thank you all!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .