节点之间的弯曲边缘,每个边缘的中间都有箭头符号 tikz

节点之间的弯曲边缘,每个边缘的中间都有箭头符号 tikz

我想用 TikZ 绘制此图像:

在此处输入图片描述

我写了这段代码:

\documentclass{standalone}

\usepackage{amsmath,amsfonts,amssymb,amsthm}

\usepackage{tikz}

\usetikzlibrary{decorations.pathreplacing,decorations.markings}
\usetikzlibrary{arrows,automata}
\usetikzlibrary{calc}



\tikzset{dot/.style = 
{circle,
draw=blue,
line width=.5pt},
dot/.default = 4pt
}

\tikzset{
  % style to apply some styles to each segment of a path
  on each segment/.style={
    decorate,
    decoration={
      show path construction,
      moveto code={},
      lineto code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
      curveto code={
        \path [#1] (\tikzinputsegmentfirst)
        .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..
        (\tikzinputsegmentlast);
      },
      closepath code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
    },
  },
  % style to add an arrow in the middle of a path
  mid arrow/.style={postaction={decorate,decoration={
        markings,
        mark=at position .5 with {\arrow[scale=1.5,#1]{stealth}}
      }}},
}

\begin{document}

\begin{tikzpicture}[line cap=round]

  % First, define nodes
  \draw (0, 0) node[
                            inner sep=0pt,
                            fill=black,
                            label={left:{$\boldsymbol{M}$}}
                            ] (M) {};  
  \draw (2, -2) node[
                            inner sep=0pt,
                            fill=black,
                            label={above:{$\boldsymbol{Q}$}}
                            ] (Q) {};  
  \draw (5, -1) node[
                            inner sep=0pt,
                            fill=black,
                            label={above:{$\boldsymbol{P}$}}
                            ] (P) {}; 
  \draw (4, 1.5) node[
                            inner sep=0pt,
                            fill=black,
                            label={right:{$\boldsymbol{O}$}}
                            ] (O) {}; 
  \draw (1, 1.5) node[
                            inner sep=0pt,
                            fill=black,
                            label={above:{$\boldsymbol{N}$}}
                            ] (N) {}; 

  % Draw curved path
  \path [very thick, draw=black, postaction={very thick, on each segment={mid arrow=black}}]
  (M) to [bend left=100] (N)
  (M) to [bend left=40] (N)
  (M) -- (N)
  (M) to [bend right=40] (N)
  (M) to [bend right=100] (N);

\end{tikzpicture}

\end{document}

结果(无红色圆圈): 在此处输入图片描述

按照圆的规定,边的主边和端点与形状不相似。有没有更简单更好的方法来做到这一点?

答案1

我必须承认,我迷失在你的 MWE 中,所以我决定从头开始编写它,以便它尽可能与提供的草图相似。但是,图像的代码更简单、更短(至少在我看来),图像更漂亮(再次符合我的品味):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                decorations.markings,
                ext.arrows,    % defined in the tikz-ext package 
                positioning}

\tikzset{dot/.style = {circle, fill, thick, inner sep=2pt, outer sep=0pt,
                       node contents={} },
  every edge/.style = {draw, thick,  
                       decoration={markings,
                                   mark=at position 0.5 with {\arrow[very thick,scale=0.6] {Centered Straight Barb}}
                                 },
                        postaction={decorate},
                       },
 every label/.style = {anchor=center, label distance = 1.7ex},
         bend angle = 25
        }% end of tikzset

\begin{document}
    \begin{tikzpicture}
% First, define nodes
\foreach \i [count=\j from 0] in {M,Q,P,O,N}
    \path (0,0) -- (180+\j*72:2) node[label=180+\j*72:\i] (\i) [dot];
% Draw curved arrows
\draw
  (M) edge [bend  left=55] (N)
  (M) edge [bend  left] (N)
  (M) edge (N)
  (M) edge [bend right] (N)
  (M) edge [bend right=55] (N);
\draw
  (N) edge [bend  left] (O)
  (N) edge [bend right] (O);
\draw
  (O) edge [bend  left=55] (P)
  (O) edge [bend  left] (P)
  (O) edge [bend right] (P)
  (O) edge [bend right=55] (P);
\draw
  (M) edge [bend  left] (Q)
  (M) edge (Q)
  (M) edge [bend right] (Q);
\draw
  (Q) edge [bend  left] (P)
  (Q) edge (P)
  (Q) edge [bend right] (P);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

不确定这是否是您的意思,所以很快您就可以用其他方式指定曲线。

% Draw curved path
  \path [very thick, draw=black, postaction={very thick, on each segment={mid arrow=black}}]
  (M) .. controls +(-1.25,1) and +(-1,1) .. (N)
  (M) to [bend left=40] (N)
  (M) -- (N)
  (M) to [bend right=40] (N)
  (M)  .. controls +(1,-1) and +(1.25,-1) .. (N);

曲线更加弯曲

相关内容