我如何正确定义角度,以便能够用它们进行计算?
我尝试了以下代码来获得以下结果,但是代码无法编译。
我不想写,而是想像下面这样0.5\bdangle+0.5\dsangle
写。更棘手的是:我如何将绿点设置在它的位置?0.5*(\bdangle+\dsangle)
2/3*(\inangle+\mmangle)
\documentclass[tikz,border=5]{standalone}
\newlength{\outerradius}\setlength{\outerradius}{10cm}
\newlength{\innerradius}\setlength{\innerradius}{9cm}
\newlength{\radiusstep}\setlength{\radiusstep}{5mm}
\newcommand{\bdangle}{90}
\newcommand{\dsangle}{190}
\newcommand{\mmangle}{230}
\newcommand{\inangle}{330}
\begin{document}
\begin{tikzpicture}
\node[fill, circle, radius=1mm] at (0,0) {};
\draw (0,0) circle[radius=\innerradius];
\draw (0,0) circle[radius=\outerradius];
\node[fill=yellow, circle] at (\bdangle:0.5\outerradius+0.5\innerradius) {a};
\node[fill=yellow, circle] at (\dsangle:0.5\outerradius+0.5\innerradius) {b};
\node[fill=yellow, circle] at (\mmangle:0.5\outerradius+0.5\innerradius) {c};
\node[fill=yellow, circle] at (\inangle:0.5\outerradius+0.5\innerradius) {d};
\node[fill=red, circle] at (0.5\bdangle+0.5\dsangle):\innerradius-\radiusstep) {};
\node[fill=blue, circle] at (2/3*(\inangle+(1-2/3)*\mmangle):\innerradius-\radiusstep) {};
\node[fill=green, circle] at (0.5*(\bdangle+360-\inangle):\innerradius-\radiusstep) {};
\end{tikzpicture}
\end{document}
答案1
加载calc
库,然后将完整的操作括在花括号中{}
(常规括号不起作用),否则 TikZ 会认为这2/3
是一个形状名称,但显然它不是。
\node[fill=red, circle] at ({0.5*\dsangle+0.5*\bdangle}:\innerradius-\radiusstep) {};
\node[fill=blue, circle] at ({2/3*\inangle+(1-2/3)*\mmangle)}:\innerradius-\radiusstep) {};
\node[fill=green, circle] at ({0.5*(\bdangle+\inangle)+180)}:\innerradius-\radiusstep) {};
输出
代码
\documentclass[tikz,margin=10pt]{standalone}
\newlength{\outerradius}\setlength{\outerradius}{10cm}
\newlength{\innerradius}\setlength{\innerradius}{9cm}
\newlength{\radiusstep}\setlength{\radiusstep}{5mm}
\newcommand{\bdangle}{90}
\newcommand{\dsangle}{190}
\newcommand{\mmangle}{230}
\newcommand{\inangle}{330}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node[fill, circle, radius=1mm] at (0,0) {};
\draw (0,0) circle[radius=\innerradius];
\draw (0,0) circle[radius=\outerradius];
\node[fill=yellow, circle] at (\bdangle:0.5\outerradius+0.5\innerradius) {a};
\node[fill=yellow, circle] at (\dsangle:0.5\outerradius+0.5\innerradius) {b};
\node[fill=yellow, circle] at (\mmangle:0.5\outerradius+0.5\innerradius) {c};
\node[fill=yellow, circle] at (\inangle:0.5\outerradius+0.5\innerradius) {d};
\node[fill=red, circle] at ({0.5*\dsangle+0.5*\bdangle}:\innerradius-\radiusstep) {};
\node[fill=blue, circle] at ({2/3*\inangle+(1-2/3)*\mmangle)}:\innerradius-\radiusstep) {};
\node[fill=green, circle] at ({0.5*(\bdangle+\inangle)+180)}:\innerradius-\radiusstep) {};
\end{tikzpicture}
\end{document}