5

In a tikzpicture, I want to draw a circular arc that is almost all of a circle from one point to another. I have the coordinates of the start and end points and the radius I would like, but I do not know where to put the center of the circle. Naively, I expect that using draw with bend=N with N being slightly less than 360 would give the result I want, but when N exceeds 90, bend behaves as if a smaller number was given and the arc is more or less straight from the start point to the end point. However, given the plethora of features in Tikz, I expect that there is some straightforward way to get this effect.

In my particular application, the arc starts downward from the bottom of a node, circles around and ends downward into the top of the same node. My current best version is

\documentclass{amsart}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\node (box) at (0,-2) {$foo$};
\draw [->] (box.south)
      to [out=260,in=100,looseness=10]
      node [midway,left=0pt] {$bar$}
      (box.north);
\end{tikzpicture}

\end{document}

where "foo" is the text in the node and "bar" is a label on the arc. But it produces an elliptical arc rather than a circular arc:

Tikz output

5
  • Do you look for a circle, or for a loop (a non-circle) ?
    – MS-SPO
    Commented Aug 15, 2023 at 15:04
  • If you want a circular arc, use the arc syntax. Commented Aug 15, 2023 at 15:13
  • 1
    Drawing a true circular arc with a curve is tedious, however with arc it is a bit annoying to figure out where the arc should start and end, depending on how you specify the circle the arc lies on. Commented Aug 15, 2023 at 15:17
  • Q679153 and its answers show a few possibilites (as part of a TikZ-CD but that's not really important). If it's okay that the arc starts exactly at the bottom and the top with a given radius, this is really easy. If you want the circle the arc lies on to go through the node's center, it gets interesting. Especially if the circle doesn't go straight to the left or the right. Can you clarify how the arc is defined? Commented Aug 15, 2023 at 15:18
  • You can create an elliptical arc. It uses a separate x and y radius and the (starting) point is given by ({\rx*cos(\t)}, {\ry*sin(\t)}) for some angle \t. In fact, \atan2(y/ry, x/rx) for point (x,y). Commented Aug 15, 2023 at 16:33

4 Answers 4

6

If you just want to specify two points and a radius you can use the ext.paths.arcto library of my tikz-ext package.

Since there exist two circles with one radius through two points and thus four arcs, you will need to specify which arc one you want by using, in this case, the large and the clockwise flag.

Code

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{ext.paths.arcto}
\begin{document}
\begin{tikzpicture}
\node (box) at (0,-2) {$foo$};
\draw [->] (box.260) arc to[radius=1cm, large, clockwise]
  node [midway, left] {$bar$} (box.100);
\end{tikzpicture}
\end{document}

Output

enter image description here

1
  • Annoyingly, I can load the library but "arc to" fails. I suspect it's because my TeX installation is quite old. ``` ! Undefined control sequence. \tikz@do@arcB ... \fi \endgroup \pgfutil@ifxempty \pgf@marshal {}{\edef \tik... l.8 node [midway, left=0pt] {$bar$} (box.100) ; ```
    – Dale
    Commented Aug 21, 2023 at 21:54
3

Building on DraUX's answer, you can get Tikz to calculate start/end angles based on the radius. In this case:

\documentclass{amsart}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\node (box) at (0,-2) {$foo$};
\draw [->]
 let \n1={1cm},
 \p1=($(box.north)-(box.south)$),
 \n2={asin(\y1/(2*\n1))},
 \n3={360-\n2} in
 \pgfextra{\xdef\cstart{\n3}} \pgfextra{\xdef\cend{\n2}}
 (box.south) arc (\cstart:\cend:\n1) node [midway,left=0pt] {$bar$};
\end{tikzpicture}

\end{document}

Here, I have used \pgfextra to make the values of \n2 and \n3 visible globally (as \cstart and \cend). You can omit the \pgfextra's if you say "arc (\n3:\n2:\n1)".

1

You can achieve it by doing something like that

\documentclass{standalone}
\usepackage{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \node (box) at (0,-2) {$foo$};
    \draw (box.south) arc (160:-160:-0.7) node [midway,left=0pt] {$bar$};
\end{tikzpicture}
\end{document}

It works, but it is an ugly solve, since you have to change the start and end angles when you change the radius.

enter image description here

1
  • To be more exact, you have to fiddle with the start and end to match the radius (or fiddle with the radius to match the start and end). But you can get Tikz to calculate it; see my answer.
    – Dale
    Commented Aug 16, 2023 at 15:24
1

Like this:

enter image description here

with a minimal code (the line of grid is optional):

\documentclass[tikz,border=1cm]{standalone}

\begin{document}
    \begin{tikzpicture}
        \draw[gray!20] (-6,-6) grid (6,6);
        \draw[line width=3pt,latex-] (5:5) arc(5:355:5);
        \node at (0:5) {\Large foo};
        \node at (180:5.5) {\Large bar};
    \end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .