座標中的三角函數不起作用

座標中的三角函數不起作用

我正在嘗試預先計算 cos 和 sin 值並在座標中使用它們。

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\def\n{13}
\def\c{\pgfmathparse{cos(5*pi/\n)}\pgfmathresult}
\def\s{\pgfmathparse{sin(5*pi/\n)}\pgfmathresult}

\node (A) at (0,0) {A};
\node (B) at (\c,0) {B};
\node (C) at (\s,0) {C};
\end{tikzpicture}

\end{document}

但是,當我嘗試編譯上面的程式碼時,出現以下錯誤:! Incomplete \iffalse; all text was ignored after line 11.

答案1

歡迎來到 TeX.SX!您需要注意 PGF 中的三角函數採用度而不是弧度這一事實。例如,sin(pi r)如果您想要輸入以弧度為單位的值,則可以使用 。除此之外,我建議您使用\pgfmathsetmacroTi提供的kZ/PGF 將數學結果儲存在巨集中:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\pgfmathsetmacro{\n}{13}
\pgfmathsetmacro{\c}{cos(5*pi/\n r)}
\pgfmathsetmacro{\s}{sin(5*pi/\n r)}

\node (A) at (0,0) {A};
\node (B) at (\c,0) {B};
\node (C) at (\s,0) {C};

% only to show the math results
\node[above of=B, rotate=90] {\c};
\node[above of=C, rotate=90] {\s};

\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容