# Wrong computation with PGF math

all.

I'm trying to draw an incircle to a regular pentagon. Here's my code:

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

\usetikzlibrary{calc, math}

\begin{document}
\begin{tikzpicture}[rotate=90]
\pgfmathsetmacro{\R}{2}
\node[draw, circle, fill=black, thick, inner sep=0pt, outer sep=0pt] (0,0) (O) {};
%\draw (O) circle (\R);
\draw[fill=blue!10!white] %
(0:\R) %node[fill=black, thick, inner sep=1pt, outer sep=1pt] {}
\foreach \x in {72,144,...,360} {
-- (\x:\R)
}
-- cycle;% (90:\R);
\foreach \x in {0,72, 144, ..., 360} {
\draw[thick, densely dashed, %rotate=90
] (O) -- (\x:\R);
}
\draw[dotted] (O) -- (180:{0.8*\R}) node[label={below:$l$}] (B) {};
\node[anchor=north west] at (180:{0.4*\R}) {$a$};
\node[anchor=south] at (216:{0.6*\R}) {$r$};
\coordinate (c) at (B);
\draw[%rotate around={72:(c)}
] ($(c) + (0.15,-0.01)$) -- ($(c) + (0.15,0.15)$) -- ($(c) + (0,0.15)$);
\pgfmathsetmacro{\ap}{cos(pi/5)*\R}
\draw[thin, densely dotted] (O) circle (\ap);
\end{tikzpicture}
\end{document}


The whole problem lies in the last two lines. The computation cos(pi/5)*\R should give around 1.618, but when drawing a circle with that radius it gives the radius of the circumcircle (see attached picture). Perhaps I have a syntax error in using the PGF math library, but I cannot see it. Naturally, when I manually input 1.618 into the radius, it draws what I want.

Thanks!

The pgfplots manual (pp. 52) recommends to use deg if you want to use radians inside a trigonometric function.

Thus, the code becomes:

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

\usetikzlibrary{calc, math}

\begin{document}
\begin{tikzpicture}[rotate=90]
\pgfmathsetmacro{\R}{2}
\node[draw, circle, fill=black, thick, inner sep=0pt, outer sep=0pt] (0,0) (O) {};
%\draw (O) circle (\R);
\draw[fill=blue!10!white] %
(0:\R) %node[fill=black, thick, inner sep=1pt, outer sep=1pt] {}
\foreach \x in {72,144,...,360} {
-- (\x:\R)
}
-- cycle;% (90:\R);
\foreach \x in {0,72, 144, ..., 360} {
\draw[thick, densely dashed, %rotate=90
] (O) -- (\x:\R);
}
\draw[dotted] (O) -- (180:{0.8*\R}) node[label={below:$l$}] (B) {};
\node[anchor=north west] at (180:{0.4*\R}) {$a$};
\node[anchor=south] at (216:{0.6*\R}) {$r$};
\coordinate (c) at (B);
\draw[%rotate around={72:(c)}
] ($(c) + (0.15,-0.01)$) -- ($(c) + (0.15,0.15)$) -- ($(c) + (0,0.15)$);
\pgfmathsetmacro{\ap}{cos(deg{pi/5})*\R};
\draw[thin, densely dotted] (O) circle (\ap);
\end{tikzpicture}
\end{document}


And here's the output:

• Quite! Thank you! Aug 14, 2021 at 0:14
• In that particular case, you could have used cos(36)*\R, alternatively. Aug 14, 2021 at 7:57
• It is about TikZ syntax, not pgfplots. From code of OP, just add \pgfmathsetmacro{\ap}{cos(pi/5 r)*\R}. Recall using cos(\x r) for \x in radians Aug 15, 2021 at 0:56