6

I have a diagram that is simply a set of nodes distributed evenly around a circle. How can I connect the nodes with arrows that are circular?

e.g., suppose we have a pentagon with nodes at each vertex. Obviously the vertices of the pentagon all lay on a circle. I want to connect the nodes by arrows that are "parallel" to the circle. (so overall it looks like a cycle)

0

4 Answers 4

10

Here is a possibility: using twice nodes of type regular polygon, one internal and the other one external, both placed on circles.

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\newcommand{\polygonsides}{5}

\begin{document}
\begin{minipage}[t][0.3\textheight]{0.45\textwidth}
Clockwise [option \texttt{bend left}]:
\begin{flushleft}
\begin{tikzpicture}
% Internal cirlce with polygon
\draw[blue](0,0)circle(1.5cm);
\node[regular polygon, regular polygon sides=\polygonsides, minimum size=3cm, draw, name=x] at (0,0) {};
% Nodes on vertices
\foreach \corner in {1,2,...,\polygonsides}
\node[circle,ball color=blue] at (x.corner \corner){};

% External polygon
\node[regular polygon, regular polygon sides=\polygonsides, minimum size=4cm, draw=none, name=p] at (0,0) {};
% Invisible nodes on vertices
\foreach \corner in {1,2,...,\polygonsides}
\node at (p.corner \corner){};

% Connections
\foreach \source/\destination in {p.corner 1/p.corner 5,p.corner 5/p.corner 4,p.corner 4/p.corner 3,p.corner 3/p.corner 2,p.corner 2/p.corner 1}
\draw[-stealth,shorten <=0.2cm,shorten >=0.2cm,thick,blue](\source)to[bend left](\destination);
\end{tikzpicture}
\end{flushleft}
\end{minipage} 
\begin{minipage}[t][0.3\textheight]{0.55\textwidth}
Counterclockwise [option \texttt{bend right}]:
\begin{flushleft}
\begin{tikzpicture}
% Internal cirlce with polygon
\draw[red](0,0)circle(1.5cm);
\node[regular polygon, regular polygon sides=\polygonsides, minimum size=3cm, draw, name=x] at (0,0) {};
% Nodes on vertices
\foreach \corner in {1,2,...,\polygonsides}
\node[circle,ball color=red] at (x.corner \corner){};

% External polygon

\node[regular polygon, regular polygon sides=\polygonsides, minimum size=4cm, draw=none, name=p] at (0,0) {};

% Nodes on vertices
\foreach \corner in {1,2,...,\polygonsides}
\node at (p.corner \corner){};

% Connections
\foreach \source/\destination in {p.corner 1/p.corner 2,p.corner 2/p.corner 3,p.corner 3/p.corner 4,p.corner 4/p.corner 5,p.corner 5/p.corner 1}
\draw[-stealth,shorten <=0.2cm,shorten >=0.2cm,thick,red](\source)to[bend right](\destination);
\end{tikzpicture}
\end{flushleft}
\end{minipage} 
\end{document}

Result:

enter image description here

The external polygon is not drawn because it's just used as reference to set properly the vertices that are the starting and ending point of arrows. Of course, it is possible to make arrows more near the polygon by declaring a closer radius for this external polygon: now the distance is 1cm. In the following there are two examples: in the first arrows are clockwise while in the second they are counterclockwise. To achieve these two things are necessary:

  • using options bend left for clockwise and bend right for counterclockwise;
  • connect the pair source/destination in clockwise order or in counterclockwise order taking in mind that nodes are vertices are numbered in counterclockwise order:

enter image description here

1
8

A compact version (didn't automate the circumference calc since I am not sure if this what is asked)

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,decorations.markings}

\begin{document}
\begin{tikzpicture}[decoration={
    markings,
    mark=between positions 0 and 1 step 2.51376 cm with {\arrow{latex}}
    }
]
\draw[postaction={decorate}] (90:2cm) arc (-270:90:2cm);
\node[draw,red,regular polygon, regular polygon sides=5,minimum height=4cm] {};
\end{tikzpicture}
\end{document}

enter image description here

7

In the following, I use the library shapes.geometric that defines a shape called regular polygon so that you have a general solution no matter how many sides the polygon has. I also need a auxiliary macro \pgfmathsetlenghtbetweenanchors that computes the lenght between two anchors of the same node.

To draw the arc, I use the syntax given here and I need the angle between two corners as mentioned here.

enter image description here

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}

\makeatletter
\def\pgfmathsetlenghtbetweenanchors#1#2#3#4{%
  % #1: length
  % #2: node
  % #3: first anchor
  % #4: second anchor
  \pgfpointdiff{%
    \pgfpointanchor{#2}{#3}}{%
    \pgfpointanchor{#2}{#4}}%
  \pgfmathparse{veclen(\pgf@x,\pgf@y)}%
  #1=\pgfmathresult pt}
\makeatother

\newlength\nagonradius

\begin{tikzpicture}
  \def\nsides{5}%
  \node[regular polygon,
        regular polygon sides = \nsides,
        draw,
        rotate=25,
        minimum size = 3cm] (\nsides-agon) {};

  \pgfmathsetlenghtbetweenanchors\nagonradius{\nsides-agon}{center}{%
    corner 2}% 
  \foreach \n [remember = \n as \m (initially \nsides)] in
    {1,...,\nsides} {%
      \pgfmathanglebetweenpoints{%
        \pgfpointanchor{\nsides-agon}{center}}{%
        \pgfpointanchor{\nsides-agon}{corner \m}}%
      \let\anglem\pgfmathresult
      \pgfmathanglebetweenpoints{%
        \pgfpointanchor{\nsides-agon}{center}}{%
        \pgfpointanchor{\nsides-agon}{corner \n}}%
      \let\anglen\pgfmathresult
      \ifdim\anglen pt < \anglem pt
        \pgfmathparse{\anglen + 360}%
        \let\anglen\pgfmathresult
      \fi
      \draw[->,red] ([shift={(\anglem:\nagonradius)}]\nsides-agon.center) arc
        (\anglem:\anglen:\nagonradius);} 

\end{tikzpicture}

\begin{tikzpicture}
  \def\nsides{7}%
  \node[regular polygon,
        regular polygon sides = \nsides,
        draw,
        rotate=25,
        minimum size = 3cm] (\nsides-agon) {};

  \pgfmathsetlenghtbetweenanchors\nagonradius{\nsides-agon}{center}{%
    corner 2}% 
  \foreach \n [remember = \n as \m (initially \nsides)] in
    {1,...,\nsides} {%
      \pgfmathanglebetweenpoints{%
        \pgfpointanchor{\nsides-agon}{center}}{%
        \pgfpointanchor{\nsides-agon}{corner \m}}%
      \let\anglem\pgfmathresult
      \pgfmathanglebetweenpoints{%
        \pgfpointanchor{\nsides-agon}{center}}{%
        \pgfpointanchor{\nsides-agon}{corner \n}}%
      \let\anglen\pgfmathresult
      \ifdim\anglen pt < \anglem pt
        \pgfmathparse{\anglen + 360}%
        \let\anglen\pgfmathresult
      \fi
      \draw[->,red] ([shift={(\anglem:\nagonradius)}]\nsides-agon.center) arc
        (\anglem:\anglen:\nagonradius);} 

\end{tikzpicture}


\end{document}
2

Here is a solution using arc:

enter image description here

And the code:

\documentclass{standalone}
\usepackage{tikz}
\pgfmathsetmacro{\radius}{2}
\begin{document}
\foreach \nbn in {3,5,7,9}{
  \begin{tikzpicture}
    \pgfmathsetmacro{\angle}{360/\nbn}
    % center
    \node {\nbn{} nodes};
    % draw nodes
    \foreach \i in {1,...,\nbn}{
      \node at (\angle*\i:\radius) {$N_\i$};
    }
    % draw arrows (clockwise)
    \foreach \i in {1,...,\nbn}{
      \draw[-latex,very thick,red!50!black]
      ({\angle*(\i+.2)}:\radius-.2)
      arc (\angle*(\i+.2):\angle*(\i+1-.2):\radius-.2);
    }

    % draw arrows (anticlockwise)
    \foreach \i in {1,...,\nbn}{
      \draw[-latex,very thick,green!50!black]
      ({\angle*(\i-.2)}:\radius+.2)
      arc (\angle*(\i-.2):\angle*(\i-1+.2):\radius+.2);
    }
  \end{tikzpicture}
}
\end{document}

You must log in to answer this question.

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