# How to make sure the tail of a rho-shaped graph remains on the left?

This question is a sequel to this other question, nicely solved by @marmot. The new question is due to a new situation that arises. In the new sequence 2, 12, 34, [43, 28, 25], where brackets denote the cycle, the tail ends up on the right side, presenting a backwards rho-letter.

Question. How to make sure the tail remains on the left side, resembling a rho-shaped graph?

Remark. I'd like to stress that the current picture is quite good! I consider any positive answer to this question a luxury, which I'll appreciate having.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{chains,positioning,calc,intersections}
\begin{document}

\begin{tikzpicture}[node distance=1cm]
\path[name path=big circle] (0,0) circle (\Radius cm);
\def\cyclelen{3}
\foreach \X [count=\Y] in {28,25,43}
{\node[name path global=\Y-circ,inner sep=4pt,circle]  (cn\Y) at
({-(\Y-2.5)*360/\cyclelen}:\Radius) {$\X$}; }
\foreach \Y [remember=\Y as \LastY (initially \cyclelen)]in {1,...,\cyclelen}
{
\path[name intersections={of=big circle and \LastY-circ,by={aux0,aux2},sort
by=big circle},
name intersections={of=big circle and \Y-circ,by={aux1,aux3},sort
by=big circle}];
\draw[-latex]
let \p1=($(aux0)-(0,0)$),\p2=($(aux3)-(0,0)$),
\n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)},
\n3={(ifthenelse(\n2<\n1,\n2,\n2-360)} in
}

\begin{scope}[start chain = going below,
every node/.append style={on chain,,xshift=-{cot(76)*1.5cm}},
every join/.style=latex-]
\node[below=of cn\cyclelen] (n0) {$34$};
\draw[latex-] (cn\cyclelen) -- (n0);
\node[join] (n1) {$12$};
\node[join] (n0) {$2$};
\end{scope}
\end{tikzpicture}
\end{document}

• You only need to use \node[name path global=\Y-circ,inner sep=4pt,circle] (cn\Y) at ({-(\Y-4.5)*360/\cyclelen}:\Radius) {$\X$};, i.e. replace (\Y-2.5) by (\Y-4.5). 2.5 and 4.5 represent offset angles of the first node. – user121799 Jan 8 at 20:31
• I guess it turned out quite simple. You should add that an answer as it not only answered, by taught me how to make further adjustments I might need. Thank you so much. – Joep Awinita Jan 8 at 20:33

If you want to make sure that the node is one the left, this can be achieved by setting

 \node[name path global=\Y-circ,inner sep=4pt,circle]  (cn\Y) at ({180-\Y*360/\cyclelen}:\Radius) {$\X$};


The reasons why I decided to write an answer are:

1. In my previous answer I have not considered the special case that the circle may start and end between two nodes in an "unfortunate way". (You may say that there is no point at which a circle starts or ends, which is true, but the path along which the intersections get ordered does start and end somewhere.) So changed the strategy slightly, which also speeds up the compilation a bit.
2. Besides, you do not have to count the number of entries yourself, TikZ can do that for you. So all you need to do is to enter the nodes you wish to draw via \def\mylist{28,25,43} and TikZ will do the rest.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{chains,positioning,calc,intersections}
\begin{document}

\begin{tikzpicture}[node distance=1cm]
\def\mylist{28,25,43}
\foreach \X [count=\Y] in \mylist
{\xdef\cyclelen{\Y}}
\foreach \X [count=\Y] in \mylist
{\node[name path global=\Y-circ,inner sep=4pt,circle]  (cn\Y) at
({180-\Y*360/\cyclelen}:\Radius) {$\X$}; }
\foreach \Y [remember=\Y as \LastY (initially \cyclelen)]in {1,...,\cyclelen}
{
\path[name path=arc] let \p1=($(cn\LastY.center)-(0,0)$),\p2=($(cn\Y.center)-(0,0)$),
\n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)},\n3={ifthenelse(\n2<\n1,\n2,\n2-360)}
\path[name intersections={of=arc and \LastY-circ,by=aux0},
name intersections={of=arc and \Y-circ,by=aux1}];
\draw[-latex] let \p1=($(aux0)-(0,0)$),\p2=($(aux1)-(0,0)$),
\n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)},\n3={(ifthenelse(\n2<\n1,\n2,\n2-360)}
\node[below=of cn\cyclelen] (n0) {$34$};
\node[join] (n1) {$12$};
\node[join] (n0) {$2$};