我想使用分数列表flist
来标记一些角度。它们将位于“A”的位置。
\begin{tikzpicture}
\edef\r{1}
\edef\anglist{{30,45,60,120,135,150,210,225,240,300,315,330}}
%\edef\flist{{\frac{\pi}{6}, \frac{\pi}{4}, \frac{\pi}{3}, \frac{2\pi}{3}, \frac{3\pi}{4}, \frac{5\pi}{6}, \frac{7\pi}{6}, \frac{5\pi}{4}, \frac{4\pi}{3}, \frac{5\pi}{3}, \frac{7\pi}{4}, \frac{11\pi}{6}}}
\foreach \a in{0,...,11}{
\pgfmathsetmacro{\tmp}{\flist[\ang]};
\draw[cycle1] (0,0)--({\r*cos(\anglist[\a])},{\r*sin(\anglist[\a])})node[pos=1.3]{$A$};
}
\end{tikzpicture}
我不知道错误在哪里,但是上面的代码不起作用。
答案1
tikz\foreach
构造支持成对的循环,正是为了允许您执行您想要执行的操作。
输出
代码
\documentclass[12pt,tikz]{standalone}
\begin{document}
% join this
%30 /\frac{\pi}{6},
%45 /\frac{\pi}{4},
%60 /\frac{\pi}{3},
%120/\frac{2\pi}{3},
%135/\frac{3\pi}{4},
%150/\frac{5\pi}{6},
%210/\frac{7\pi}{6},
%225/\frac{5\pi}{4},
%240/\frac{4\pi}{3},
%300/\frac{5\pi}{3},
%315/\frac{7\pi}{4},
%330/\frac{11\pi}{6},
\begin{tikzpicture}[scale=2]
\def\r{1}
\foreach \cAngle/\dAngle in {30/\frac{\pi}{6},45/\frac{\pi}{4},60/\frac{\pi}{3},120/\frac{2\pi}{3},135/\frac{3\pi}{4},150/\frac{5\pi}{6},210/\frac{7\pi}{6},225/\frac{5\pi}{4},240/\frac{4\pi}{3},300/\frac{5\pi}{3},315/\frac{7\pi}{4},330/\frac{11\pi}{6}}
{
\draw (0,0)--({\r*cos(\cAngle)},{\r*sin(\cAngle)}) node[pos=1.3]{$\dAngle$};
}
\end{tikzpicture}
\end{document}