# tikz draw circle segment

How can I use tikz to draw a circle segment if I have the center of the circle and two points on it? Please see the following example Update: I try to accomplish something like this. This can be done using the method from Tikz: joining points on a circle, but I would prefer a some sort of tikz solution, because this would allow me to use a tikz style. • Welcome to TeX.sx! You should have a look at this post. If it does not answer, your question please update it to describe how your problem is different. Dec 11, 2012 at 16:21
• yeah it works by using \pgfpathmoveto{<coordinate>} \pgfpatharcto{<x-radius>}{<y-radius>}{<rotation>}{<large arc flag>}{<counterclockwise flag>}{<target point>} and then translating by the center. But is there some more intuitive way to write this in tikz? It would be great if I could easily use this with \filldraw[somestyle] Dec 11, 2012 at 17:18
• Can you add a minimal working example (MWE) that shows which points you want to connect. There are a few ways to do this. For an arc there exists arc[<opt>]. Dec 11, 2012 at 17:33
• Sure I can create a MWE (tomorrow). In short: I have all the black points in the second figure, and want to create the green object. Dec 11, 2012 at 17:44 Using calc library and the operators let and in you can compute the radius, initial angle and final angle for the arc from the three points you have (center and two circle points), and use then the computed numbers as part of the path. The following MWE shows how:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\thispagestyle{empty}
\usetikzlibrary{calc}

\begin{tikzpicture}
\coordinate (center) at (3,3);
\coordinate (1) at (0,0);
\coordinate (2) at (5, .5);
\coordinate (3) at ($(center) +(30:2)$);
\coordinate (4) at ($(center) +(70:2)$);
\coordinate (5) at (0,6);

\draw[blue, dotted]
let \p1 =  ($(3)-(center)$),
\n0 = {veclen(\x1,\y1)}
in (center) circle(\n0);

\filldraw[draw=black, fill=green, fill opacity=0.3]
let \p1 = ($(3) - (center)$),
\p2 = ($(4) - (center)$),
\n1 = {atan(\y1/\x1)+180*(\x1<0)},  % initial angle
\n2 = {atan(\y2/\x2)+180*(\x2<0)}   % Final angle
in
(1) -- (2) --  (3) arc(\n1:\n2:\n0)  -- (5)  -- cycle;

\foreach \dot in {1,2,3,4,5,center} {
\fill (\dot) circle(2pt);
\node[above] at (\dot) {\dot};
}

\end{tikzpicture}
\end{document}


If you have v2.10 of pgf/tikz, you can calculate the initial and final angles using atan2(x,y) instead of the above expression, (thanks to qrrbrbirlbel for suggesting it), i.e:

       \n1 = {atan2(\x1,\y1)},  % initial angle
\n2 = {atan2(\x2,\y2)}   % Final angle

• Now, I was unable to draw the arc in red... (in the same path operation, I mean) Dec 11, 2012 at 18:02
• There is atan2(x,y) for this: \n1 = {atan2(\x1,\y1)}, \n2 = {atan2(\x2,\y2) Dec 11, 2012 at 18:08
• @Qrrbrbirlbel I cannot find atan2 in my pgf manual, and it does not work in my system nor in tlhiv.org/ltxpreview Is it a new feature? Dec 11, 2012 at 18:13
• It’s in v2.10. See the manual on page 5.3.4 (63.2.3 “Trigonometric functions”) Dec 11, 2012 at 18:18