[Tex/LaTex] How to automatically obtain the center of the circle used to draw the arc in TikZ

arctikz-pgf

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:

Mathematica graphics

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}

Mathematica graphics

PS: For illustration of the Arc API in Mathematica:

Mathematica graphics

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

Mathematica graphics

Best Answer

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}];

\draw [dashed, red] (X) ellipse [x radius=3, y radius=2];
\end{tikzpicture}
\end{document}

enter image description here

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;

\draw [dashed, red]   (X) ellipse [x radius=3, y radius=2];
\draw [dashed, green] (Y) ellipse [x radius=1, y radius=3];
\draw [dashed, blue]  (Z) ellipse [x radius=4, y radius=2];
\end{tikzpicture}

enter image description here