[Tex/LaTex] tikz draw circle segment

tikz-pgf

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

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.

enter image description here

Best Answer

Result

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)$),
       \n0 = {veclen(\x1,\y1)},            % Radius
       \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
Related Question