[Tex/LaTex] Draw arc in tikz when center of circle is specified

tikz-pgf

It would be convenient sometimes to be able to draw an arc in tikz by specifying

  • the center of the corresponding circle
  • its radius
  • the initial/final angle

i.e., the "natural" way an arc is defined, instead of the "first point of the arc".

Is there a way to do it?

Best Answer

You can use the parametrization

x(t)=a+r*cos(t)
y(t)=b+r*sin(t)

where r is the radius of the circle and (a,b) are the coordinates of its center. In Tikz this can be implemented as follows:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
   \draw [red,thick,domain=0:90] plot ({cos(\x)}, {sin(\x)});
   \draw [blue,thick,domain=180:270] plot ({cos(\x)}, {sin(\x)});
\end{tikzpicture}

\end{document}

which produces

screenshot

Depending on your application, you might like to do this using the pgfplots package.

Also, in case this is used frequently, consider defining a custom command \centerarc as suggested in a comment by Tom Bombadil (this requires \usetikzlibrary{calc}):

\def\centerarc[#1](#2)(#3:#4:#5)% Syntax: [draw options] (center) (initial angle:final angle:radius)
    { \draw[#1] ($(#2)+({#5*cos(#3)},{#5*sin(#3)})$) arc (#3:#4:#5); }

Then use it by invoking

\centerarc[red,thick](0,0)(5:85:1)
Related Question