Draw arc in tikz when center of circle is specified

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)

You should use a coordinate transformation for this, to get a proper starting point of the arc. Say, ([shift=(t:r)] x, y) is the proper starting point, where (x,y) is the center and (t:r) is the polar coordinate of starting point.

Full example:

enter image description here

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[help lines] (0,0) grid (4,3);
\draw (2,1) -- ++(30:2cm)
      (2,1) -- ++(60:2cm);
% Draw the arc which center is (2,1)
\draw[thick,red] ([shift=(30:1cm)]2,1) arc (30:60:1cm);
\end{tikzpicture}

\end{document}

Notation: each arc is defined by <center>, <radius>, <init angle> and <final angle>.

If you want to be able to link several arcs in a single path, you can use shift with following syntax:

  • initial point:([shift={(<init angle>:<radius>)}]<center>)

  • to draw your arc: arc (<init angle>:<final angle>:<radius>)

Example (orange path uses proposed syntax and cyan path uses a style):

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \draw[fill=orange]
  ([shift={(-40:1cm)}]-1.1,0) arc (-40:40:1cm)
  --
  ([shift={(-40+180:1cm)}]1.1,0) arc (-40+180:40+180:1cm)
  -- cycle;
\end{tikzpicture}
\begin{tikzpicture}
  \tikzset{translate/.style={shift={(#1)}}}
  \draw[fill=cyan]
  ([translate=-40:1cm]-1.1,0) arc (-40:40:1cm)
  --
  ([translate=-40+180:1cm]1.1,0) arc (-40+180:40+180:1cm)
  -- cycle;
\end{tikzpicture}
\end{document}

enter image description here

Edit: a simpler notation!

Using calc TikZ library, you can use a simpler notation:

  • initial point: ($(<center>) + (<init angle>:<radius>)$).

Example:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
  % center c1
  \coordinate (c1) at (0,0);

  \draw[fill=green]
  % radius=3mm, initial=0, final=90
  %([shift={(0:3mm)}]c1) arc (0:90:3mm)
  ($(c1) + (0:3mm)$) arc (0:90:3mm)
  --
  % radius=4mm, reversed
  ($(c1) + (90:4mm)$) arc (90:0:4mm)
  -- cycle;

  \draw[fill=yellow]
  % radius=4mm, initial=22.5, final=180
  ($(c1) + (22.5:4mm)$) arc (22.5:180:4mm)
  --
  % radius=5mm, reversed
  ($(c1) + (180:5mm)$) arc (180:22.5:5mm)
  -- cycle;

  % center c2
  \coordinate (c2) at (0,12mm);

  \draw[fill=red]
  % radius=5mm, initial=45, final=270
  ($(c2) + (45:5mm)$) arc (45:270:5mm)
  --
  % radius=6mm, reversed
  ($(c2) + (270:6mm)$) arc (270:45:6mm)
  -- cycle;

  \draw[fill=gray]
  % radius=6mm, initial=67.5, final=360
  ($(c2) + (67.5:6mm)$) arc (67.5:360:6mm)
  --
  % radius=7mm, reversed
  ($(c2) + (360:7mm)$) arc (360:67.5:7mm)
  -- cycle;
\end{tikzpicture}
\end{document}

enter image description here

Tags:

Tikz Pgf