答案1
pics
是非常强大的 tikz 组件,因为它们除了以与节点相同的方式处理之外还接受输入参数(尽管有细微的差别)。
\documentclass[tikz,border=2pt]{standalone}
\begin{document}
\tikzset{
pics/numcirc/.style args={#1/#2}{
code = {
\draw circle (1);
\foreach \i in {1,...,#1}
\draw (90+\i*360/#1:1) -- (90+\i*360/#1:1.5);
\foreach \i in {1,...,#2}
\draw (90+\i*360/#2:0) -- (90+\i*360/#2:0.5);
}}}
\begin{tikzpicture}
\draw pic at(0,0) {numcirc=8/6};
\draw pic at(4,0) {numcirc=6/4};
\draw pic at(8,0) {numcirc=12/8};
\end{tikzpicture}
\end{document}
答案2
这是一个起点。这个想法是使用由 给出的极坐标(我喜欢极坐标)(angle:radius)
。
\documentclass{report}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[thick]
\foreach \a in {0,45,...,315}{
\draw (\a:2)--(\a:3);
}
\foreach \a in {0,60,...,300}{
\draw[red] (0,0)--(90+\a:1.8);
}
\draw (0,0) circle (2cm);
\end{tikzpicture}
\end{document}
一些改进:感谢@AboAmmar
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\def\numA{}
\def\numB{}
\newcommand{\target}[2]{%
\renewcommand{\numA}{#1}
\renewcommand{\numB}{#2}
\begin{tikzpicture}[thick]
\foreach \i in {1,...,\numA}{%
\draw (\i*360/\numA:2) -- (\i*360/\numA:3);
}
\foreach \i in {1,...,\numB}{%
\draw[red] (0,0) -- (90+\i*360/\numB:1.7);
}
\draw (0,0)node[below=3cm]{\Large$\numA/\numB$} circle (2cm);
\end{tikzpicture}
}
\begin{document}
\target{8}{6}\target{6}{4}\target{12}{6}
\end{document}