# Draw arc in tikz when center of circle is specified

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

• the center of the corresponding circle
• 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?

-
–  Qrrbrbirlbel Nov 10 at 3:09

Or perhaps parametrically using

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


where r is the radius of the circle centered on (a,b)

\documentclass{article}
\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}


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

-
Thank you very much! –  niels Aug 7 '12 at 16:26
@niels you're welcome :) –  cmhughes Aug 7 '12 at 16:26
Clever solution! –  percusse Aug 9 '12 at 0:43
Very nice, I used the idea to define this command: \def\centerarc[#1](#2)(#3:#4:#5)% [draw options] (center) (initial angle:final angle:radius) { \draw[#1] ($(#2)+({#5*cos(#3)},{#5*sin(#3)})$) arc (#3:#4:#5); } It. can be used e.g. likr this: \centerarc[red,thick](0,0)(5:85:1) –  Tom Bombadil Aug 21 '12 at 22:35

Maybe like this (as in the pgfmanual):

\begin{tikzpicture}
\draw (0,0) -- (2,1);
\draw (2,1) -- ++(30:2cm)
(2,1) -- ++(60:2cm);
\draw (2,1) ++(30:1cm) arc (30:60:1cm);
\end{tikzpicture}

-
Oh this is very clever. I'm going to use this technique to answer my own question here –  bobobobo Aug 9 '12 at 16:53

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}


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]
%([shift={(0:3mm)}]c1) arc (0:90:3mm)
($(c1) + (0:3mm)$) arc (0:90:3mm)
--
($(c1) + (90:4mm)$) arc (90:0:4mm)
-- cycle;

\draw[fill=yellow]
($(c1) + (22.5:4mm)$) arc (22.5:180:4mm)
--
($(c1) + (180:5mm)$) arc (180:22.5:5mm)
-- cycle;

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

\draw[fill=red]
($(c2) + (45:5mm)$) arc (45:270:5mm)
--
($(c2) + (270:6mm)$) arc (270:45:6mm)
-- cycle;

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


-

Possible is to use tkz-euclide. I f you want something independent of tkz-euclide you can take the code inside the file tkz-obj-arcs.tex. In each cases, I use the center

1) \tkzDrawArc and towards

towards is the option by defaut so it's not necessary to indicate this option. In the the example, the arc starts from A towards the axe OB.

 \begin{tikzpicture}[scale=1.5]
\tkzDefPoint(0,0){O}
\tkzDefPoint(2,-1){A}
\tkzDefPoint(1,1){B}
\tkzDrawArc[color=blue](O,A)(B)
\tkzDrawArc[color=Maroon](O,B)(A)
\tkzDrawArc(O,B)(A)
\tkzDrawLines[add = 0 and .5](O,A O,B)
\tkzDrawPoints(O,A,B)
\tkzLabelPoints[below](O,A,B)
\end{tikzpicture}


2) \tkzDrawArc and rotate

Here the center is O, the arc starts from A and the measure of the angle is 180 degrees.

\begin{tikzpicture}
\tkzDefPoint(0,0){O}
\tkzDefPoint(2,-2){A}
\tkzDefPoint(60:2){B}
\tkzDrawLines[add = 0 and .5](O,A O,B)
\tkzDrawArc[rotate,color=red](O,A)(180)
\tkzDrawPoints(O,A,B)
\tkzLabelPoints[below](O,A,B)
\end{tikzpicture}


3) \tkzDrawArc and R

In this case the center is O and you need to give the radius R and two angles

\begin{tikzpicture}
\tkzDefPoints{0/0/O}
\tikzset{compass style/.append style={<->}}
\tkzDrawArc[R, color=orange,double](O,3cm)(270,360)
\tkzDrawArc[R, color=blue,double](O,2cm)(0,270)
\tkzDrawPoint(O)
\tkzLabelPoint[below](O){$O$}
\end{tikzpicture}


4) \tkzDrawArc and R with nodes In this case, we need to know the center, the radius and the arc starts from the line BA towards the line BO

\begin{tikzpicture}
\tkzDefPoint(0,0){O}
\tkzDefPoint(2,-1){A}
\tkzDefPoint(1,1){B}
\end{tikzpicture}


5) \tkzDrawArc and delta

Useful to add an arc like with a compass.

\begin{tikzpicture}
\tkzInit
\tkzDefPoint(0,0){A} \tkzDefPoint(5,0){B} \tkzDefPointBy[rotation= center A%
angle 60](B) \tkzGetPoint{C}
\tkzSetUpLine[color=gray]
\tkzDefPointBy[symmetry= center C](A)
\tkzGetPoint{D}
\tkzDrawSegments(A,B A,D)
\tkzDrawLine(B,D)
\tkzSetUpCompass[color=orange]
\tkzDrawArc[delta=10](A,B)(C)
\tkzDrawArc[delta=10](B,C)(A)
\tkzDrawArc[delta=10](C,D)(D)
\tkzDrawPoints(A,B,C,D)
\tkzLabelPoints(A,B,C,D)
\tkzMarkRightAngle(D,B,A)
\end{tikzpicture}


-

You can create a new command, like this one

\documentclass[12pt]{standalone}
\usepackage{tikz}

\newcommand{\cercle}[4]{
\node[circle,inner sep=0,minimum size={2*#2}](a) at (#1) {};
\draw[red,thick] (a.#3) arc (#3:{#3+#4}:#2);
}
\begin{document}
\begin{tikzpicture}

\coordinate (center) at (3,2);

\cercle{center}{2cm}{25}{-90}
![\cercle{4,5}{1cm}{15}{130}][1]

\end{tikzpicture}
\end{document}


-