使从节点到自身的箭头在整个弧线上具有均匀的曲率

使从节点到自身的箭头在整个弧线上具有均匀的曲率

我最近问过另一个相关问题,但认为最好再问一个问题,以便关注具体的细节:

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,snakes,automata,backgrounds,petri}
\begin{document}

\begin{tikzpicture}[node distance=1.7cm,shorten <=.4ex, shorten >=.4ex,>=latex]
\tikzstyle{place}=[circle,thick,draw=gray!75,fill=gray!20,minimum size=6mm] 

\begin{scope}
\node [place] (s){};
\draw[thick,->] (s) to [out=90,in=180,looseness=5] (s);
\end{scope}

\end{tikzpicture}

\end{document}

在此处输入图片描述

如何才能使箭头弧的曲率始终均匀同时保留对箭头起点和终点的位置和角度的控制?

答案1

具有均匀曲率的圆弧是圆的一部分。如果固定起始角和终止角,则节点的大小决定了此圆的半径,当终止角和起始角之差接近 180 度时,半径可能会变得任意大。这里有一种方法可以做到这一点。命令

\drawloop[options]{node}{start angle}{end angle} ... ;

绘制一个圆弧,从 出发nodestart angle再次从 进入end angle。圆弧在节点边界处立即开始和结束。如果要shorten绘制圆弧,请将键设置stretch为大于 1 的值(它会拉伸节点的虚拟半径)。

在此处输入图片描述

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{stretch/.initial=1}
\newcommand\drawloop[4][]%
   {\draw[shorten <=0pt, shorten >=0pt,#1]
      ($(#2)!\pgfkeysvalueof{/tikz/stretch}!(#2.#3)$)
      let \p1=($(#2.center)!\pgfkeysvalueof{/tikz/stretch}!(#2.north)-(#2)$),
          \n1= {veclen(\x1,\y1)*sin(0.5*(#4-#3))/sin(0.5*(180-#4+#3))}
      in arc [start angle={#3-90}, end angle={#4+90}, radius=\n1]%
   }
\begin{document}

\begin{tikzpicture}
\node [circle,draw,thick,fill=gray] (s) {};
\drawloop[->,stretch=1.1]{s}{70}{180} node[pos=0.5,left]{a};
\drawloop[->,stretch=1.1]{s}{270}{360};
\drawloop[->,stretch=1.1]{s}{260}{370};
\drawloop[->,stretch=1.1]{s}{250}{380} node[pos=0.5,right]{b};
\drawloop[->,stretch=1.1]{s}{240}{390} node[pos=0.5,right]{c};
\drawloop[->,stretch=1.1]{s}{230}{400};
\end{tikzpicture}

\end{document}

答案2

使用与节点相同半径的圆弧,从节点的北边开始,到节点的西边结束。如果需要指定其他半径,则需要进行一些计算。

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,decorations,automata,backgrounds,petri,bending}
\begin{document}

\begin{tikzpicture}[node distance=1.7cm,shorten <=.2ex, shorten >=.2ex,>=latex]
\tikzstyle{place}=[circle,thick,draw=gray!75,fill=gray!20,minimum size=6mm] 

\begin{scope}
\node [place] (s){};
\draw[thick,->] (s.90) arc (0:270:3mm);
\end{scope}

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容