# 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 '13 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
I don't really think this answer answers the questions, though Tom Bombadil's comment does. – mrc Feb 26 at 16:44

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:

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

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


-
How to add proper head for this filled curve to make it look likes an arrow? – CroCo Apr 3 at 2:50
@CroCo Is it a new issue? So, ask a follow-up question... – Paul Gaborit Apr 3 at 5:48

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}


-
I cannot get this code to work. I've loaded tkz-euclide, but LaTeX complains that \tkzDrawArc is not defined. Is there something else I need to load? – A.Ellett Mar 16 '14 at 14:46
You need to add in the preamble \usetkzobj{arcs} or \usetkzobj{all} – Alain Matthes Mar 16 '14 at 15:04
@AlainMatthes Would like to reproduce Example (1) in plain TeX. I looked at tkz-obj-arcs.tex, but am confused about what to extract from that to translate to plain TeX. Please advise. – user1823664 Mar 16 '14 at 18:06

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}


-
I added line width and color to your command, and I find it pretty useful and very handy! – Diegis Feb 26 at 16:22

I added line width and color to your command @rpapa, I find it pretty useful and very handy! Coupled with some very simple polar coordinates, it can handle a lot.

\documentclass{standalone}
\usepackage{tikz}

\newcommand{\cercle}[6]{
\node[circle,inner sep=0,minimum size={2*#2}](a) at (#1) {};
\draw[#6,line width=#5] (a.#3) arc (#3:{#3+#4}:#2);
}
% USAGE: \cercle {center} {radius in cm} {begin degrees} {value of the arc} {line width} {color}
% \coordinate (OO) at (2.8,2.2);
% \cercle{OO}{0.5cm}{-20}{60}{1.0pt}{blue};

\begin{document}

\begin{tikzpicture}
\coordinate (OR) at (0.00, 0.00);
\filldraw [orange] (OR) circle(2pt);
\node[above left, orange] at (OR) {\textbf{\textit{0}}};
\draw[step = 0.1cm, gray, ultra thin] (-1.5,-2) grid (1.5,2);
\draw[black, thin] (-1.5,0)--(1.5,0) (0,-2)--(0,2);
% 30 degree arc, starting at +15 degrees
\cercle {OR} {0.5cm} {15} {30} {1.00} {red};
\draw[red,thin] (OR) -- (pi/12 r:0.5);
\draw[red,thin] (OR) -- (pi/4 r:0.5);
% 75 degree arc, starting at -15 degrees
\cercle {OR} {1.0cm} {-15} {75} {1.50} {blue};
\draw[blue,thin] (OR) -- (-pi/12 r:1.0);
\draw[blue,thin] (OR) -- (pi/3 r:1.0);
% 90 degree arc, starting at -135 degrees
\cercle {OR} {1.5cm} {-135} {90} {2.00} {teal};
\draw[teal,thin] (OR) -- (-pi/4 r:1.5);
\draw[teal,thin] (OR) -- (-3*pi/4 r:1.5);
\end{tikzpicture}

\end{document}

-