[Tex/LaTex] Drawing an arc for given two endpoints, center and radius of the arc

arctikz-pgf

Consider the following code:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections, calc}

\begin{document}
    \begin{tikzpicture}[auto]
        \draw (0,0) node[below] {$P$} -- (2,0) node[below] {$Q$};
        \path[name path=circ] (3,4) node[above]  {$O$} circle (3.5);
        \path[name path=l1] (0,0) -- (0, 4);
        \path[name path=l2] (2,0) -- (2,4);

        \path[name intersections={of=l1 and circ, by=a}];
        \path[name intersections={of=l2 and circ, by=b}];
        \draw (0,0) -- (a) node[above] {$R$};
        \draw (2,0) -- (b) node[above] {$X$};

        \draw[densely dotted] (3,4) -- (3,0) node[right] {$Z$} -- (2,0);
        \draw[densely dotted] (b) -- (b -| 3,0) node[right] {$Y$} (a) -- (a -| 3,0) node[right] {$S$};
        \draw[densely dotted] (a) -- (3,4) -- (b);

        \draw[|<->|] (-0.1, 0) -- node {$H$} ($ (a) +(-.1,0) $);
        \draw[|<->|] (2.1,0) -- node[swap] {$h$} ($ (b) +(.1,0) $);

        \draw[|<->|] (0, .1) --node {$d$} (2,.1);

    \end{tikzpicture}
\end{document}

What I want to do is, to draw an arc where two endpoints are R and X, and the center of the arc is O. How can I do this by not manually calculating the angle of the two lines OR and OX?

enter image description here

Best Answer

You can use the angles-library of tikz.

Add angles to your \usetikzlibrary

\usetikzlibrary{intersections, calc, angles}

Add at the end of your code:

\coordinate (o) at (3,4);
\pic [draw, angle radius=3.5cm] {angle=a--o--b};

The points R and X are already defined by the two intersection points a and b. You just need to add a coordinate at your point O to let tikz do the work.

EDIT: Complete example with explicit coordinates

\documentclass[tikz, border=5mm]{standalone}

\usetikzlibrary{intersections, calc, angles}

\begin{document}
  \begin{tikzpicture}
    \coordinate [label=below:$P$] (p) at (0,0);
    \coordinate [label=below:$Q$] (q) at (2,0);
    \coordinate [label=above:$O$] (o) at (3,4);

    \path [name path=l1] (p) -- +(0,4);
    \path [name path=l2] (q) -- +(0,4);
    \path [name path=circ] ($(o)+(200:3.5cm)$) arc (200:260:3.5cm);

    \path [name intersections={of=l1 and circ, by=ri}];
    \path [name intersections={of=l2 and circ, by=xi}];

    \coordinate [label=above:$R$] (r) at (ri);
    \coordinate [label=above:$X$] (x) at (xi);

    \coordinate [label=right:$S$] (s) at (r-|o);
    \coordinate [label=right:$Y$] (y) at (x-|o);
    \coordinate [label=below:$Z$] (z) at (q-|o);

    \draw (r) -- (p) -- (q) -- (x);

    \begin{scope}[dotted]
        \draw (r) -- (s) (q) -- (z) -- (o) (x) -- (y) (r) -- (o) -- (x);
        \pic [draw, angle radius=3.5cm] {angle=r--o--x};
    \end{scope}

    \begin{scope}[|<->|]
        \draw ([xshift=-.1cm]r) -- ([xshift=-.1cm]p) node [midway, left] {$H$};
        \draw ([xshift=.1cm]q) -- ([xshift=.1cm]x) node [midway, right] {$h$};
        \draw ([yshift=.1cm]p) -- ([yshift=.1cm]q) node [midway, above] {$d$};
    \end{scope}
  \end{tikzpicture}
\end{document}

rendered image