# Making arrow from node to itself have uniform curvature throughout its arc

I recently asked another related question, but thought it better to ask a new one in order to focus on a specific detail:

\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}


How can I make the curvature of the arc of the arrow uniform throughout while retaining control over the position and angle of the beginning and end of the arrow?

• @gernot What a negative comment. But anyway, thank you for pointing it out. I ran the code in Sharelatex, which apparently allows the mistake. I fixed it now. Feb 16, 2017 at 17:51
• Sorry, didn't mean to be rude. It only really surprises me each time when the code provided in a post runs into all kinds of strange errors. But Sharelatex with its settings is an explanation that I didn't think of. As compensation I can offer you the code for drawing such uniformly curved arcs for arbitrary angles, see my answer. Feb 16, 2017 at 18:31
• @gernot No problem, and thank you, that is very generous of you :) Feb 16, 2017 at 21:31

An arc with uniform curvature is a segment of a circle. If you fix the start and the end angle, then the size of the node determines the radius of this circle, which may become arbitrarily big as the difference of end and start angle approaches 180 degrees. Here is a way to do it. The command

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


draws a circular arc leaving node at the start angle and entering again at the end angle. The arc starts and ends immediately at the node border. If the arc is supposed to be shortened, set the key stretch to a value bigger than one (it stretches the virtual radius of the node).

\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}

• I changed the accept to this answer, since it provides a more widely applicable code. Feb 16, 2017 at 21:36

Use an arc with the same radius as the node starting at its north and ending at its west. If you need to specify another radius, some calculations are required.

\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}