我想在 Tikz 上绘制下图:
我尝试使用此代码,但线条扭曲了:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[yscale=0.6,xscale=0.6]
\def\n{24}
\def\nst{6}
\coordinate (O) at (0,0);
\draw[black, line width=1mm] (0,0) circle (5);
\draw[line width=0.3mm] (0,0) circle (1);
\draw (7.5,0) node [anchor=east][inner sep=0.75pt] {$A_Z = 0$};
\foreach \angle in {1,...,\n}{%
\pgfmathsetmacro\compute{\angle*360/\n}
\begin{scope}[rotate around={\compute:(O)}]
\draw (3.5,0) -- ++(0:0.5) arc (0:7.5:3.5) -- ++(7.5:-0.5) arc (0:7.5:3);
\draw (4,0) arc (0:7.5:4);
\end{scope}
}
\foreach \angle in {1,...,\nst}{%
\pgfmathsetmacro\compute{\angle*360/\nst}
\begin{scope}[rotate around={\compute:(O)}]
\draw (2,0) -- ++ (0:0.3) arc (0:-10:2) -- ++ (0:0.5);
\end{scope}
}
\end{tikzpicture}
\end{document}
有人可以给我一些建议并帮助我吗?
答案1
这是有可能的。除了蓝线之外,其他都很简单。对于它们,我calc
之前使用库计算了一些坐标(旋转scope
)。
这是我的代码:
\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,thick,rotate=30]
\draw[line width=1mm,fill=gray!15] (0,0) circle (5);
\draw[red,fill=white] (-1.5:4) foreach\i in {0,10,...,350} {arc (\i-1.5:\i+1.5:4) -- (\i+1.5:3.5) arc (\i+1.5:\i+8.5:3.5) -- (\i+8.5:4)};
\foreach\i in {1,2,...,6}
{
\begin{scope}[rotate=60*\i-60]
\coordinate (A\i) at (-10:2.5);
\coordinate (B\i) at ($(A\i)+(0.4,0)$);
\coordinate (C\i) at ($(A\i)+(0.4,-0.2)$);
\coordinate (D\i) at ($(A\i)+(0.6,-0.2)$);
\coordinate (H\i) at (10:2.5);
\coordinate (G\i) at ($(H\i)+(0.4,0)$);
\coordinate (F\i) at ($(H\i)+(0.4,0.2)$);
\coordinate (E\i) at ($(H\i)+(0.6,0.2)$);
\end{scope}
}
\draw[blue,fill=blue!20] (A1) \foreach\i in {1,...,6}
{-- (B\i) -- (C\i) -- (D\i) to[out=60*\i+10,in=60*\i+230]
(E\i) -- (F\i) -- (G\i) -- (H\i) arc (60*\i-50:60*\i-10:2.5)};
\draw[fill=white] (0,0) circle (1.5);
\end{tikzpicture}
\end{document}
编辑2:稍微解释一下语法。让我们看一下这一行
\draw[red,fill=white] (-1.5:4) foreach\i in {0,10,...,350} {arc (\i-1.5:\i+1.5:4) ...};
这将从点 开始绘制一条复杂路径(-1.5:4)
,即极坐标为半径 4(距原点 4 厘米)和角度 -1.5(距 x 轴 1.5 度,顺时针)的点。然后它将重复花括号内的代码六次,替换\i
值0,60,120,180,240,300
。例如,第一次迭代将是\i=0
,所以
\draw[red,fill=white] (-1.5:4) arc (0-1.5:0+1.5:4) ...;
因此,复杂路径的第一部分arc
将从初始角度为 -1.5 度、最终角度为 1.5 度且半径为 4 厘米的点开始(-1.5:4)
。在这种情况下,所有角度都以原点为中心,但有关圆弧中心的更多信息,此帖子可能会有所帮助:TikZ 中如何定义圆弧?