# How do I create a loop based on a series of points in TikZ as in the Graph style?

I am currently working on a project to create a translator from Frank Drewes' graph style into TikZ.

As an example, I am trying to recreate the following diagram from the graph style manual into a TikZ diagram.

The code for the above in Graph style is:

\begin{graph}(4,4)(-2,0)
\squarenode{Sq}(-1.5,3.5)
\textnode{Te}(1.5,3.5){abc}
\roundnode{Ro}(0,.5)
\diredge{Sq}{Te}
\edge{Sq}{Ro} \diredge{Ro}{Te}
\dirbow{Ro}{Sq}{-.2}
\dirbow{Ro}{Te}{.2}
\dirloopedge{Ro}(-.8,-.2)(-1.2,.4)
\dirloopedge{Ro}(.8,-.2)(1.2,.4)
\loopedge{Ro}{15}(0,-.5)
\end{graph}


Most of these commands are easy to translate; however, I am having a lot of trouble with the "loopedge" and "dirloopedge" commands.

The description of the "loopedge" command from the manual is as follows:

\loopedge{name}(x1,y1)(x2,y2)

A loop at node name. The coordinates (x1,y1) and (x2,y2) are interpreted as relative coordinates of the endpoints of two edge halves starting in name. During drawing, these are connected by a curve to obtain a loop.

There does not seem to be a command anything like this in TikZ and, in fact, drawing loops seems to be really difficult. My problem is further compounded by a lack of documentation in the graph style manual as to how the connecting curve is actually produced.

Can anyone help me?

-

I'm not sure exactly what method is used to obtain the curve drawn by \dirloopedge (for some reason, the asymmetric support points in your example seem to yield a symmetric curve). Below is a macro that has the same form as that in "Graph Style".

It draws a straight line from the start node to the first support point and from the second support curve to the start node, with a curve between the two support points with the out and in angles equal to the angles of the straight line segments. You might want to adjust the looseness parameter, which determines the radius of the curve.

\documentclass{article}
\usepackage{tikz}

\def\dirloopedge#1(#2,#3)(#4,#5){
\pgfpointxy{#2}{#3}
\pgfgetlastxy{\ax}{\ay}
\pgfmathsetmacro\outangle{atan2(#2,#3)}
\pgfmathsetmacro\inangle{atan2(#4,#5)}

\draw [-latex] (#1) -- +(#2,#3) to [out=\outangle,in=\inangle,looseness=5]  +(#4,#5) -- (Ro);
}

\begin{document}
\begin{tikzpicture}

\node (Ro)  at (0,0.5) [fill,circle,inner sep=2pt] {};

\dirloopedge{Ro}(0.8,-0.2)(0.8,0.2)

\end{tikzpicture}
\end{document}


-