# [Tex/LaTex] Filling angles with arcs in TikZ

tikz-pgf

Using TikZ, how can I fill in an angle of a given polygon with a colored arc? For example, given the triangle

\filldraw[fill=yellow, draw=black] (10,0) -- (-2,9) -- (4,-3) -- (10,0);

I'd like a blue arc of radius 1 centered on (10,0) sweeping out the angle bounded by the sides of the triangle.

Edit: I forgot an important part of my question, which (I think) makes the links provided in the comments insufficient.

How can I fill only half the angle with a shaded arc?

Here is something that gets the job done using basic tikz commands. One of the experts will probably be able to make something nice of it. One major problem is the limitations on number size in tikz computations. The triangle you asked about has dimensions that make the computations too big for tikz to handle properly (pstricks wouldn't have that problem), that is why I used another triangle.

Once the coordinates for the corners are given, the angles are computed automatically, using the let operation. The code is

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}

\coordinate (A) at (1,0);
\coordinate (B) at (-2,1);
\coordinate (C) at (2,3);

\filldraw[fill=yellow, draw=black] (A) node {$\bullet$} -- (B) -- (C) -- cycle;

\draw[->] let \p{AB} = ($(B)-(A)$),
\p{AC} = ($(C)-(A)$),
\n{lAB} = {veclen(\x{AB},\y{AB})},
\n{lAC} = {veclen(\x{AC},\y{AC})},
\n{angAB} = {atan2(\x{AB},\y{AB})},
\n{cos} = {(\x{AB}*\x{AC}+\y{AB}*\y{AC})/(\n{lAB}*\n{lAC})},
\n{angle} = {acos(\n{cos})} in
($(A)+0.2*(\p{AB})$) arc[radius={0.2*\n{lAB}},start angle=\n{angAB},delta angle=-\n{angle}];

\end{tikzpicture}

\end{document}


and the result is

To actually get a (half-)shaded arc, replace the draw command by the following code

\shadedraw[fill=blue] let \p{AB} = ($(B)-(A)$),
\p{AC} = ($(C)-(A)$),
\n{lAB} = {veclen(\x{AB},\y{AB})},
\n{lAC} = {veclen(\x{AC},\y{AC})},
\n{angAB} = {atan2(\x{AB},\y{AB})},
\n{cos} = {(\x{AB}*\x{AC}+\y{AB}*\y{AC})/(\n{lAB}*\n{lAC})},
\n{angle} = {acos(\n{cos})} in
(A) -- ++ ($0.2*(\p{AB})$) arc[radius={0.2*\n{lAB}},start angle=\n{angAB},delta angle={-\n{angle}/2}] -- cycle;


With this code, the result is

Another modification of the code, that does not use cosine and arccosine is

\draw[->] let \p{AB} = ($(B)-(A)$),
\p{AC} = ($(C)-(A)$),
\n{lAB} = {veclen(\x{AB},\y{AB})},
\n{lAC} = {veclen(\x{AC},\y{AC})},
\n{angAB} = {atan2(\x{AB},\y{AB})},
\n{angAC} = {atan2(\x{AC},\y{AC})},
\n{angle} = {mod(\n{angAB}-\n{angAC},180)} in
($(A)+0.2*(\p{AB})$) arc[radius={0.2*\n{lAB}},start angle=\n{angAB},delta angle=-\n{angle}];