尝试用节点画一个圆圈

尝试用节点画一个圆圈

我正在尝试在 Tikz 中绘制以下图像在此处输入图片描述

但我得到的只是

在此处输入图片描述

我无法将其变成一个完美的圆圈。代码是

  \documentclass[tikz,border=2mm]{standalone} 
  \begin{document}
  \begin{tikzpicture}
  \coordinate (O) at (0,0);
  \coordinate (A) at (60:1cm);
  \coordinate (B) at (180:1cm);
  \coordinate (C) at (300:1cm);
  \node at (O) {$+1$}; 
  \node at (A) {$1$}; 
  \node at (B) {$2$}; 
  \node at (C) {$3$};

  \draw[->] (A) to [bend right] (B);
  \draw[->] (B) to [bend right] (C);
  \draw[->] (C) to [bend right] (A);  
  \end{tikzpicture}
  \end{figure*}     
  \end{document}

提前致谢。

答案1

使用tkz-euclide

在此处输入图片描述

\documentclass[border=3mm]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}
  \tkzDefPoint(0,0){O}
  \tkzDefPoint(60:1){A}
  \tkzDefPoint(180:1){B}
  \tkzDefPoint(300:1){C}

  \tikzset{compass style/.append style={orange,line width=0.7mm,-stealth}}
  \tkzDrawArc[delta=-10](O,A)(B) 
  \tkzDrawArc[delta=-10](O,B)(C)
  \tkzDrawArc[delta=-10](O,C)(A)

  \node[orange] at (O) {\textbf{+1}}; 
  \node[blue] at (A) {\textbf{1}}; 
  \node[blue] at (B) {\textbf{2}};
  \node[blue] at (C) {\textbf{3}};

 \end{tikzpicture}
\end{document} 

答案2

只是为了好玩:弧线确实围绕圆运行,不需要任何硬编码角度,即弧线会根据节点的大小进行调整,因为它们的端点是根据圆与节点边界的交点计算出来的。代码或多或少取自这里.还请注意箭头是弯曲的。

\documentclass[border=5mm,tikz]{standalone}
\usetikzlibrary{arrows.meta,bending,calc,intersections}
\begin{document}
\begin{tikzpicture}[nodes={circle,text=blue,execute at begin node=$,
execute at end node=$},
 pics/circular arc/.style args={from #1 to #2}{code={
 \path[name path=arc] 
  let \p1=(#1),\p2=(#2),\n1={Mod(720+atan2(\y1,\x1),360)},
  \n2={Mod(720+atan2(\y2,\x2),360)},
    \n3={ifthenelse(abs(\n1-\n2)<180,\n2,\n2+360)}
  in (\n1:\r) arc(\n1:\n3:\r);
 \draw[pic actions,
    name intersections={of=#1 and arc,by=arcstart},
    name intersections={of=#2 and arc,by=arcend}] 
    let \p1=(arcstart),\p2=(arcend),\n1={Mod(720+atan2(\y1,\x1),360)},
     \n2={Mod(720+atan2(\y2,\x2),360)},
     \n3={ifthenelse(abs(\n1-\n2)<180,\n2,\n2+360)}
  in (\n1:\r) arc(\n1:\n3:\r);
 }}]
\def\r{1}
% 3 nodes with possibly different sizes
\path
(0:\r) node[name path=p1] (p1) {1}
(120:\r)  node[name path=p2] (p2) {2}
(240:\r)   node[name path=p3] (p3) {3}
(0,0) node[orange]{+1};
\begin{scope}[thick,orange,-{Stealth[bend]}]
 \path pic{circular arc=from p1 to p2}
     pic{circular arc=from p2 to p3}
     pic{circular arc=from p3 to p1};
\end{scope}
\begin{scope}[xshift=4cm]
\path
(0:\r) node[name path=p1] (p1) {1}
(120:\r)  node[name path=p2] (p2) {2}
(240:\r)   node[name path=p3] (p3) {3}
(0,0) node[red] {-1};
\begin{scope}[thick,red,{Stealth[bend]}-]
 \path pic{circular arc=from p1 to p2}
     pic{circular arc=from p2 to p3}
     pic{circular arc=from p3 to p1};
\end{scope}
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

或者一切都在一个pic。那么就足以说例如

\path (-2,2) pic[circular diagram/arcs=orange]{circular diagram={1,2,3}}
node[orange]{$+1$};

完整 MWE:

\documentclass[border=5mm,tikz]{standalone}
\usetikzlibrary{arrows.meta,bending,calc,intersections}
\begin{document}
\begin{tikzpicture}[nodes={circle},
 pics/circular arc/.style args={from #1 to #2}{code={
 \path[name path=arc] 
  let \p1=(#1),\p2=(#2),\n1={Mod(720+atan2(\y1,\x1),360)},
  \n2={Mod(720+atan2(\y2,\x2),360)},
    \n3={ifthenelse(abs(\n1-\n2)<180,\n2,\n2+360)}
  in (\n1:\pgfkeysvalueof{/tikz/circular diagram/radius}) arc(\n1:\n3:\pgfkeysvalueof{/tikz/circular diagram/radius});
 \draw[pic actions,
    name intersections={of=#1 and arc,by=arcstart},
    name intersections={of=#2 and arc,by=arcend}] 
    let \p1=(arcstart),\p2=(arcend),\n1={Mod(720+atan2(\y1,\x1),360)},
     \n2={Mod(720+atan2(\y2,\x2),360)},
     \n3={ifthenelse(abs(\n1-\n2)<180,\n2,\n2+360)}
  in (\n1:\pgfkeysvalueof{/tikz/circular diagram/radius}) arc(\n1:\n3:\pgfkeysvalueof{/tikz/circular diagram/radius});
 }},
pics/circular diagram/.style={code={
\foreach \XX [count=\YY starting from 1] in {#1}
{\xdef\mydim{\YY}};
\path foreach \XX [count=\YY starting from 0] in {#1}
{({\pgfkeysvalueof{/tikz/circular diagram/offset angle}+\YY*360/\mydim}:%
\pgfkeysvalueof{/tikz/circular diagram/radius}) node[name path=aux-\YY] (aux-\YY) {\XX} };
\path[circular diagram/parc] foreach \XX [evaluate=\XX as \YY using {int(mod(\XX+1,\mydim))}]
in {0,...,\the\numexpr\mydim-1}
{pic{circular arc=from {aux-\XX} to aux-\YY} 
};}},circular diagram/.cd,offset angle/.initial=0,radius/.initial=1,
parc/.style={thick,-{Stealth[bend]}},
arcs/.code={\tikzset{circular diagram/parc/.append style={#1}}}
]
\path (-2,2) pic[circular diagram/arcs=orange]{circular diagram={1,2,3}}
    node[orange]{$+1$}
    (2,2) pic[circular diagram/arcs={red,{Stealth[bend]}-}]{circular diagram={1,2,3}}
    node[red]{$-1$}
    (-2,-2) pic[circular diagram/.cd,arcs=purple,offset angle=45]{circular
    diagram={$a$,$b$,$c$,$d$}}
    node[purple]{$+1$}
    (2,-2) pic[circular diagram/arcs={cyan,{Stealth[bend]}-}]{circular
        diagram={$a$,$b$,$c$,$d$}}
    node[cyan]{$-1$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

下面在节点周围的圆上使用静态 8 度间隙。因此,它对当前节点内容很有效,但可能需要进行调整才能真正适合用例(或者有人可能会想出一种算法来计算这一点)。

\documentclass[border=3.14,tikz]{standalone}

\begin{document}
\begin{tikzpicture}
  \node {$+1$};
  \foreach[count=\n]\x in {-60, 60, 180}
    {
      \node (\n) at (\x:1) {$\n$};
      \draw[<-] (\x+8:1) arc[start angle=\x+8, end angle=\x+112, radius=1cm];
    }
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案4

pstricks 解决方案:

    \documentclass[svgnames, border =2cm]{standalone}

    \usepackage{pst-node, pst-eucl, multido, auto-pst-pdf}

    \begin{document}

    \sffamily\bfseries
    \begin{pspicture}(-2,-2)(2,2)
        \psset{linewidth=1.5pt, arrowinset=0.12, nodesep =4pt}
        \multido{\i=1+1, \iangle=-60 + 120, \iangles=-54+121, \ianglet=53+120}{3}{%
        \rput(1.5; \iangle){\rnode{N\i}{\color{RoyalBlue}\i}}\pnode(1.5; \iangles){S\i}\pnode(1.5; \ianglet){T\i}%
        \pstArcOAB[linecolor=Gold, arrows= <-]{O}{S\i}{T\i}%
        \rput(0,0){\color{Gold} +1}
        }%
    \end{pspicture}
    \begin{pspicture}(-2,-2)(2,2)
        \psset{linewidth=1.5pt, arrowinset=0.12, nodesep =4pt}
        \multido{\i=1+1, \iangle=-60 + 120, \iangles=-54+121, \ianglet=54+120}{3}{%
        \rput(1.5; \iangle){\rnode{N\i}{\color{RoyalBlue}\i}}\pnode(1.5; \iangles){S\i}\pnode(1.5; \ianglet){T\i}%
        \pstArcOAB[linecolor=Crimson, arrows=->]{O}{S\i}{T\i}%
        \rput(0,0){\color{Crimson} --1}
        }%
    \end{pspicture}

    \end{document} 

在此处输入图片描述

相关内容