Below is a graph I drew using TikZ, which achieves the purpose. However, I feel that my code is still not concise enough because it uses four for-loops. Is there a more concise method?
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=0.8]
% Define the center point
\coordinate (u) at (0,0);
% Draw the vertex u
\node[draw, circle, fill=blue, inner sep=1pt] (u0) at (u) {$u$};
% Draw the first circle with radius 1
%\draw [blue](u) circle (1);
% Draw the second circle with radius 1.5
%\draw (u) circle (1.5);
% Draw vertices on the radius 1 circle and connect them to the center
\foreach \angle/\label in {54/v_0, -18/v_2, -90/v_4, 198/v_6, 126/v_8}
{
\node[draw, circle, fill=white, inner sep=0pt] (w\angle) at ({cos(\angle)}, {sin(\angle)}) {$\label$};
\draw (u0) -- (w\angle);
}
% Draw vertices on the radius 1.5 circle and connect them to the center
\foreach \angle\label in {18/v_1, 90/v_9, 162/v_7, 234/v_5,-54/v_3}
{
\node[draw, circle, fill=orange, inner sep=0pt] (w\angle) at ({1.5*cos(\angle)}, {1.5*sin(\angle)}) {$\label$};
\draw[blue] (u0) -- (w\angle);
}
% Draw vertices on the radius 1.2 circle and connect them to the center
\foreach \angle [remember=\angle as \lastangle (initially 198)] in {-90, -18, 54, 126, 198}
{
\draw[blue] (w\lastangle) -- (w\angle);
}
\foreach \angle [remember=\angle as \lastangle (initially 234)] in {-90, -54, -18, 18, 54, 90, 126,162, 198, 234}
{
\draw[thick] (w\lastangle) -- (w\angle);
}
\end{tikzpicture}
\end{document}
Is it possible to reduce the number of loops to make the code more structured?
Best Answer
With two loops and two additional lines:
(you may check if
w6
andw8
labels are interchanged ...)At least above code is quite sorter than yours :-)
Addendum:
with just one loop and
\ifodd
macro fromTeX
:Result is the same as before.