
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の三角関数はラジアンではなく度数を取ることに注意する必要があります。ラジアンで値を入力する場合は、たとえば を使用できます。それ以外では、 Tiが提供するsin(pi r)
を使用することをお勧めします。\pgfmathsetmacro
けマクロに数学的結果を格納するための Z/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}