# How to automatically obtain the center of the circle used to draw the arc in TikZ?

The TikZ arc command is a little unusual, since the center of the circle used is not actually specified in the API. The API does not follow standard arc construction. From example, in Mathematica, to draw an arc, one gives the center of the circle, radius, and the two angles.

But these four parameters are defined indirectly in TikZ arc, in a roundabout way. Only the radius and two angles are specified, but not the center of the circle.

So it was a struggle to find where the center that is used is located to understand how the arc came about.

The best help I found that explains the formula is in the second answer to How is arc defined in TikZ?. Here is screenshot of the formula:

I verified it is correct below. My two questions are:

(1) Once I make an arc, is there a way to automatically ask TikZ to tell me the center of the circle used for making the arc, instead of me having to calculate it from the above formula?

(2) Does there exist another arc command in TikZ or library that uses the more normal API: center of circle, radius, and two angles? Since it is easier for me to use that.

MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\fbox{
\begin{tikzpicture}
\draw (-2,0)--(2,0) ;  %  Draw axes
\draw (0,-2)--(0,2) ;

\def\x{1}   %Define arc API, as in (x,y) arc (from,to,r)
\def\y{0}
\def\r{1}
\def\from{-25}
\def\to{45}

%Now draw the arc
\draw[color=blue,line width=1mm] (\x,\y) arc (\from:\to:\r);

%Calculate its center from the formula above
\coordinate (c) at ({\x + \r * cos(\from + 180)},{\y + \r * sin(\from + 180)});

%Draw the circle used to get the arc from
\draw[color=red,thin] (c) circle (\r);
\draw[fill] (c) circle({0.05*\r});
\end{tikzpicture}
}
\end{document}


PS: For illustration of the Arc API in Mathematica:

So, to draw an arc with circle at (0,0), radius 1, and from -25 degrees to 45 degrees, the command is

x = 0; y = 0; r = 1; theta1 = -25 Degree; theta2 = 45 Degree;
Graphics[Circle[{x, y}, r, {theta1, theta2}], Axes -> True,
AspectRatio -> Automatic, AxesOrigin -> {0, 0}]


• duplicate? tex.stackexchange.com/questions/66216/… Feb 7, 2015 at 15:24
• @DavidCarlisle thanks for the link. But for question (1), how to obtain the center coordinates from Tikz, it is not the same question? but for (2), it seems to have what I want, yes. Feb 7, 2015 at 15:27

Only part of what was required. But it also shows how a key with the required syntax could be programmed:

\documentclass[tikz,border=5]{standalone}
\tikzset{%
insert arc/.style args={#1:#2:#3and#4 with center #5}{
insert path={
\pgfextra{%
\pgfpointxy{#3}{#4}%
\pgfgetlastxy\arcrx\arcry%
\pgfcoordinate{#5}{%
\pgfpoint{\csname tikz@lastx\endcsname+\arcrx*cos(#1+180)}%
{\csname tikz@lasty\endcsname+\arcry*sin(#1+180)}}
}
arc (#1:#2:#3 and #4)
}
}
}

\begin{document}
\begin{tikzpicture}[rotate=40]
\draw [very thick] (0,0)  [insert arc={-25:45:3 and 2 with center X}];

\end{tikzpicture}
\end{document}


And a slightly more comprehensive example:

\begin{tikzpicture}
\draw [very thick] (0,0) -- (0,1)
[insert arc={270:135:3 and 2 with center X}] -- (-4,4)
[insert arc={ 10:-90:1 and 3 with center Y}]
[insert arc={180:360:4 and 2 with center Z}] -- cycle;

\end{tikzpicture}


There is no standard arc construction API anyways. Arcs are graphics objects, as is with PostScript or SVG they can be concatenated to an existing path object and there is no need for a center declaration since last known point is the start point of the arc and the rest is computed implicitly. Otherwise you cannot do stuff like this

\tikz\draw (0,0) --++(45:1) arc (135:90:1) arc (90:-90:0.5) -- cycle;


Everybody would be going crazy to find those two center points just to draw this simple figure so it is a very very good thing. Having said that, Postscript has arc and arcn operators that requires a center point and PGF has \pgfpatharctoprecomputed.

In any case you don't need any information since you know the arc start angle and the radius. Hence you know what the normal is or you have the formula already. Mathematica does something completely different so there is no need to have a consistent syntax.

If you need this more often (why I can't predict) use circular nodes and draw on their borders and refer to the node center.

• Arcs are graphics objects, Ok, but the common understanding or arc is that it is segment of circle or ellipse. It looks like tikz uses a more advanced definition of arc being segment of any general "curve". Thanks for your answer. Feb 7, 2015 at 16:19
• @Nasser Not quite. They are still parts of ellipse and circle otherwise they are Bezier curves but as a format, PDF or PS doesn't work like a geometric engine. Everything, including the letters themselves, relies on paths. So mathematica can not be the standard setter here. You can force a syntax as Mark did but it will still boil down to path concatenation. Feb 7, 2015 at 20:23