Skip to content

Instantly share code, notes, and snippets.

@loopspace
Created December 17, 2021 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loopspace/321721de1af3929b9d8de77d906511f3 to your computer and use it in GitHub Desktop.
Save loopspace/321721de1af3929b9d8de77d906511f3 to your computer and use it in GitHub Desktop.
Circlular graph with arcs joining nodes
\documentclass{article}
\usepackage{tikz}
% These libraries handle the path manipulations
\usetikzlibrary{
intersections,
spath3
}
\begin{document}
% Don't use \[...\] just to centre something
\begin{center}
% \tikzstyle is depreciated
\begin{tikzpicture}[
every node/.style={
font=\small,
draw,
circle,
minimum size=.75cm
},
r-out/.style={
draw,
very thick,
red,
-stealth,
},
r-btw/.style={
draw,
very thick,
blue,
},
]
% Declare the nodes and save their outlining paths (needs global) as
% node paths are buried deep in a group
\node[spath/save global=e] (e) at (0:2) {\(1\)};
\node[spath/save global=r] (r) at (90:2) {\(r\)};
\node[spath/save global=r2] (r2) at (180:2) {\(r^2\)};
\node[spath/save global=r3] (r3) at (270:2) {\(r^3\)};
\node[spath/save global=f] (f) at (0:1) {\(f\)};
\node[spath/save global=rf] (rf) at (90:1) {\(r f\)};
\node[spath/save global=r2f] (r2f) at (180:1) {\(r^2 f\)};
\node[spath/save global=r3f] (r3f) at (270:1) {\(r^3 f\)};
% Define the circular paths
\path[spath/save=outer circle] (0,0) circle[radius=2];
\path[spath/save=inner circle] (0,0) circle[radius=1];
% Draw the paths between the inner and outer nodes
\foreach \nd in {r,r2,r3}
{
\draw[r-btw] (\nd) -- (\nd f);
}
\draw[r-btw] (e) -- (f);
% This set of commands splits the outer and inner circles where they
% meet the node boundaries so that the components inside the
% boundaries can be removed.
\tikzset{
% Circles have an empty component at the start
spath/remove empty components=outer circle,
spath/remove empty components=inner circle,
% Split at the various intersections
spath/split at intersections with={outer circle}{e},
spath/split at intersections with={outer circle}{r},
spath/split at intersections with={outer circle}{r2},
spath/split at intersections with={outer circle}{r3},
spath/split at intersections with={inner circle}{f},
spath/split at intersections with={inner circle}{rf},
spath/split at intersections with={inner circle}{r2f},
spath/split at intersections with={inner circle}{r3f},
% Remove the components corresponding to the pieces inside the nodes
spath/remove components={outer circle}{2,4,6,8},
spath/remove components={inner circle}{2,4,6,8},
% We want to render these separately to get the arrows
spath/get components of={outer circle}\ocircleCpts,
spath/get components of={inner circle}\icircleCpts
}
% Iterate over the components and draw each one
\foreach \cpt in \ocircleCpts {
\draw[r-out,spath/use=\cpt];
}
\foreach \cpt in \icircleCpts {
\draw[r-out,spath/use=\cpt];
}
% Just to show that the arcs are circles
\draw (0,0) circle[radius=2] circle[radius=1];
\end{tikzpicture}
\end{center}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment