如何确保 rho 形图的尾部保持在左侧?

如何确保 rho 形图的尾部保持在左侧?

这个问题是这个问题的后续其他问题,@marmot 很好地解决了这个问题。新问题是由于出现了新情况。在新序列 2、12、34、[43、28、25] 中,括号表示循环,尾部最终位于右侧,呈现出反向的 rho 字母。

在此处输入图片描述

问题。如何确保尾部保持在左侧,类似于 rho 形图?

评论。我想强调的是,目前的情况相当不错!我认为对这个问题的任何肯定回答都是一种奢侈,我会很感激。

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

\begin{tikzpicture}[node distance=1cm]
\pgfmathsetmacro{\Radius}{3.5}
\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 
(aux0) arc(\n1:\n3:\Radius);
}

\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}

答案1

如果你想确保节点位于左侧,可以通过设置来实现

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

我决定写答案的原因是:

  1. 在我之前的回答中,我没有考虑到圆可能以“不幸的方式”在两个节点之间开始和结束的特殊情况。(您可能会说圆没有开始或结束的点,这是真的,但是交叉点排序的路径确实在某个地方开始和结束。)因此,稍微改变了策略,这也加快了编译速度。
  2. 此外,你不必亲自计算条目的数量,TiZ 可以帮你做到这一点。所以你需要做的就是输入你想要绘制的节点\def\mylist{28,25,43}Ti绘制的节点剩下的事由 Z 来做。

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

\begin{tikzpicture}[node distance=1cm]
\pgfmathsetmacro{\Radius}{3.5}
\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)}
in (cn\LastY.center) arc(\n1:\n3:\Radius);
\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)} 
in (aux0) arc(\n1:\n3:\Radius);
}
\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}

在此处输入图片描述

相关内容