具有五个节点和循环的图

具有五个节点和循环的图

我该如何创建这个图表?假设每个节点到各个方向都有权重。抱歉,示例画得不好,提前感谢您的帮助!

有五个节点的图

答案1

正确的方法是使用 Ti 自带的图形绘制库Z,快速而肮脏的方法是将其画成一个循环。如果你想要有关正确方法的更多信息,请向我们展示你尝试过的方法。这是快速而肮脏的方法(但弧形箭头对于正确方法也可能有用)。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,bending,decorations.markings}
\tikzset{% https://tex.stackexchange.com/a/430239
    arc arrow/.style args={%
    to pos #1 with length #2}{
    decoration={
        markings,
         mark=at position 0 with {\pgfextra{%
         \pgfmathsetmacro{\tmpArrowTime}{#2/(\pgfdecoratedpathlength)}
         \xdef\tmpArrowTime{\tmpArrowTime}}},
        mark=at position {#1-\tmpArrowTime} with {\coordinate(@1);},
        mark=at position {#1-2*\tmpArrowTime/3} with {\coordinate(@2);},
        mark=at position {#1-\tmpArrowTime/3} with {\coordinate(@3);},
        mark=at position {#1} with {\coordinate(@4);
        \draw[-{Stealth[length=#2,bend]}]       
        (@1) .. controls (@2) and (@3) .. (@4);},
        },
     postaction=decorate,
     }
}
\begin{document}
\begin{tikzpicture}[bullet/.style={fill,circle,inner sep=2pt},
bent arrow/.style={arc arrow=to pos #1 with length 2mm}]
 \path foreach \X in {1,...,5} {
 (-72+90+72*\X:3) node[bullet] (p\X){}};
 \foreach \X [evaluate=\X as \NextX using {int(mod(\X,5)+1)},
  evaluate=\X as \NextNextX using {int(mod(\X+1,5)+1)},] in {1,...,5} {
 \draw[bent arrow=0.55] (p\X) to[out=-72+110+72*\X,in=-72+180+72*\X] 
 ++ (-72+90+72*\X:1.25) to[out=-72+72*\X,in=-72+70+72*\X] (p\X);
 \draw[bent arrow=0.55] (p\X) to[out=-72+180+72*\X,in=72*\X,looseness=0.8] (p\NextX);
 \draw[bent arrow=0.55] (p\NextX) to (p\X);
 \draw[bent arrow=0.35] (p\NextNextX) to (p\X);
 \draw[bent arrow=0.35] (p\X) to (p\NextNextX);}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容