PGF 数学计算错误

PGF 数学计算错误

全部。

我正在尝试绘制一个正五边形的内切圆。这是我的代码:

\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}

整个问题都出在最后两行。计算结果cos(pi/5)*\R应该在 1.618 左右,但当用该半径绘制圆时,它会给出外接圆的半径(见附图)。也许我在使用 PGFmath库时有语法错误,但我看不到它。当然,当我手动将 1.618 输入半径时,它会绘制我想要的。

谢谢!

输出

答案1

deg如果您想在三角函数中使用弧度,则建议使用 pgfplots 手册(第 52 页) 。

因此,代码变成:

\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}

输出如下: 我的 LaTeX 输出

相关内容