这个问题源于此其他问题,其中@marmot 很好地解决了这个问题。但是,该解决方案假设循环将始终具有大约 11 个节点数。当您将该解决方案应用于具有 4 个节点的循环时,循环看起来更像一个正方形。
我们如何才能让这些箭头看起来更像一个圆圈?理想情况下,它看起来像一个椭圆,半径尽可能接近 $rho$ 字母,但圆形就很好了。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{chains,positioning}
\begin{document}
\begin{tikzpicture}[node distance=1cm]
\node[circle,minimum width=7cm] (circ) {};
\foreach \X [count=\Y] in {32,25,50,17}
{\node (cn\Y) at ({-(\Y-2.5)*360/4}:3.5) {$\X$}; }
\foreach \Y [remember=\Y as \LastY (initially 4)]in {1,...,4}
{\draw[-latex,shorten >=4pt,shorten <=4pt] (cn\LastY) to[bend left=10] (cn\Y);}
\begin{scope}[start chain = going below,
every node/.append style={on chain,,xshift=-{cot(76)*1.5cm}},
every join/.style=latex-]
\node[below=of cn4] (n0) {$36$};
\draw[latex-] (cn4) -- (n0);
\node[join] (n6) {$9$};
\node[join] (n5) {$1$};
\node[join] (n4) {$24$};
\node[join] (n3) {$4$};
\node[join] (n2) {$46$};
\node[join] (n1) {$12$};
\node[join] (n0) {$2$};
\end{scope}
\end{tikzpicture}
\end{document}
答案1
抱歉造成混淆。我没有考虑过任意数量的节点,但我应该考虑。这是一个在精确的圆上绘制连接的版本。(在 Zarko 的回答中,仍然有一些参数需要手动调整。然而,对于长弧来说,arc
s 看起来确实比 更好bend left
。)缺点是编译需要一段时间。
\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);
\foreach \X [count=\Y] in {32,25,50,17}
{\node[name path global=\Y-circ,inner sep=4pt,circle] (cn\Y) at
({-(\Y-2.5)*360/4}:\Radius) {$\X$}; }
\foreach \Y [remember=\Y as \LastY (initially 4)]in {1,...,4}
{
\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 cn4] (n0) {$36$};
\draw[latex-] (cn4) -- (n0);
\node[join] (n6) {$9$};
\node[join] (n5) {$1$};
\node[join] (n4) {$24$};
\node[join] (n3) {$4$};
\node[join] (n2) {$46$};
\node[join] (n1) {$12$};
\node[join] (n0) {$2$};
\end{scope}
\end{tikzpicture}
\end{document}
或者,可以找到近似值输入到左弯中。以下代码编译速度更快,但不会生成精确的圆。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{chains,positioning,calc}
\begin{document}
\begin{tikzpicture}[node distance=1cm]
\pgfmathsetmacro{\Radius}{3.5}
\foreach \X [count=\Y] in {32,25,50,17}
{\node[inner sep=4pt,circle] (cn\Y) at
({-(\Y-2.5)*360/4}:\Radius) {$\X$}; }
\foreach \Y [remember=\Y as \LastY (initially 4)]in {1,...,4}
{
\path (cn\LastY) -- (cn\Y) coordinate[pos=0](aux0) coordinate[pos=1](aux1);
\draw[-latex]
let \p1=($(aux0)-(0,0)$),\p2=($(aux1)-(0,0)$),
\n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)},
\n3={0.45*(\n1-ifthenelse(\n2<\n1,\n2,\n2-360)} in
(cn\LastY) to[bend left=\n3] (cn\Y);
}
\begin{scope}[start chain = going below,
every node/.append style={on chain,,xshift=-{cot(76)*1.5cm}},
every join/.style=latex-]
\node[below=of cn4] (n0) {$36$};
\draw[latex-] (cn4) -- (n0);
\node[join] (n6) {$9$};
\node[join] (n5) {$1$};
\node[join] (n4) {$24$};
\node[join] (n3) {$4$};
\node[join] (n2) {$46$};
\node[join] (n1) {$12$};
\node[join] (n0) {$2$};
\end{scope}
\end{tikzpicture}
\end{document}