我想画一个圆盘,在圆盘上用小线进行划分,在某些选定的地方用小圆盘代替线条。
例如,一个圆盘被分成九个部分,其中七个部分用小线表示,其中两个部分用黑色小圆盘表示而不是线条。我该如何用 tikz 绘制它?
我可以绘制如下所示的圆盘:
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\def\NumSpokes{8}
\def\InnerR{2.9}
\def\OuterR{3}
\draw (0,0) circle (\OuterR); \foreach \k in {1,...,\NumSpokes}
{%
\draw (\k*360/\NumSpokes:\InnerR) -- (\k*360/\NumSpokes:\OuterR+0.1) ; }
\end{tikzpicture}
\end{document}
但我想在主磁盘上有小线条的地方添加一些黑色的小圆盘。
答案1
你的意思是:
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\def\NumSpokes{8}
\def\InnerR{2.9}
\def\OuterR{3}
\draw (0,0) circle (\OuterR); \foreach \k in {1,...,\NumSpokes}
{%
\draw (\k*360/\NumSpokes:\InnerR) -- (\k*360/\NumSpokes:\OuterR+0.1) ; }
\foreach \k in {3,6,7}{%
\fill[black] (\k*360/\NumSpokes:\OuterR) circle (0.1);
}
\end{tikzpicture}
\end{document}
编辑:
最后关于距离的评论之后:
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
\def\NumSpokes{8}
\def\InnerR{2.9}
\def\OuterR{3}
\draw (0,0) circle (\OuterR); \foreach \k in {1,...,\NumSpokes}
{%
\draw (\k*360/\NumSpokes:\InnerR) -- (\k*360/\NumSpokes:\OuterR+0.1) ; }
\foreach \k in {3,6,7}{%
\fill[black] (\k*360/\NumSpokes:\OuterR) circle (0.1) ;
\coordinate (Cir\k) at (\k*360/\NumSpokes:\OuterR) ;
}
\draw[dashed] (3*360/\NumSpokes:\OuterR)--(6*360/\NumSpokes:\OuterR);
\draw[dashed] (3*360/\NumSpokes:\OuterR)--(7*360/\NumSpokes:\OuterR);
\draw[dashed] (6*360/\NumSpokes:\OuterR)--(7*360/\NumSpokes:\OuterR);
%distances
\draw [decorate,decoration={brace,mirror,amplitude=10pt}]
(Cir3) -- (Cir6);
\node at ({(3+6)/2*360/\NumSpokes}:1.7) {$L_1$} ;
\draw [decorate,decoration={brace,amplitude=10pt}]
(Cir3) -- (Cir7);
\node at ({(3+7)/2*360/\NumSpokes}:-0.7) {$L_2$} ;
\draw [decorate,decoration={brace,mirror,amplitude=10pt}]
(Cir6) -- (Cir7);
\node at ({(6+7)/2*360/\NumSpokes}:3.5) {$L_3$} ;
\end{tikzpicture}
\end{document}
距离可以改进,也可以计算为自动...但你明白了。
最后编辑:
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
\def\NumSpokes{8}
\def\InnerR{2.9}
\def\OuterR{3}
\draw (0,0) circle (\OuterR); \foreach \k in {1,...,\NumSpokes}
{%
\draw (\k*360/\NumSpokes:\InnerR) -- (\k*360/\NumSpokes:\OuterR+0.1) ; }
\foreach \k in {3,6,7}{%
\fill[black] (\k*360/\NumSpokes:\OuterR) circle (0.1) ;
\coordinate (Cir\k) at (\k*360/\NumSpokes:\OuterR) ;
}
\draw let \p1=(Cir3) in (\x1,3.4) -- (\x1,3.6);
\draw let \p2=(Cir6) in (\x2,3.4) -- (\x2,3.6);
\draw let \p3=(Cir7) in (\x3,3.4) -- (\x3,3.6);
\draw[dotted] let \p1=(Cir3) in (\x1,\y1) -- (\x1,3.6);
\draw[dotted] let \p2=(Cir6) in (\x2,\y2) -- (\x2,3.6);
\draw[dotted] let \p3=(Cir7) in (\x3,\y3) -- (\x3,3.6);
\draw[dashed] let \p1=(Cir3), \p2=(Cir7) in (\x1,3.5) -- (\x2,3.5);
%distances
\draw [decorate,decoration={brace,amplitude=10pt}]
let \p1=(Cir3), \p2=(Cir6) in (\x1,3.7)-- (\x2,3.7)node[midway,above,shift={(0,0.3)}]{$L_1$};
\draw [decorate,decoration={brace,amplitude=10pt}]
let \p1=(Cir6), \p2=(Cir7) in (\x1,3.7)-- (\x2,3.7)node[midway,above,shift={(0,0.3)}]{$L_2$};
\end{tikzpicture}
\end{document}
答案2
如果我理解正确的话,也许就是这样?
我使用该ifthen
包在循环中进行了测试。对于值 3 和 7,循环会构建一个圆圈而不是一条小线。
\documentclass[border=5pt]{standalone}
\usepackage{ifthen}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\def\NumSpokes{8}
\def\InnerR{2.9}
\def\OuterR{3}
\draw (0,0) circle (\OuterR);
\foreach \k in {1,...,\NumSpokes}
{\ifthenelse{\k=3}{\draw (\k*360/\NumSpokes:\OuterR)circle(2pt); }
{\ifthenelse{\k=7}{\draw (\k*360/\NumSpokes:\OuterR)circle(2pt); }
{\draw (\k*360/\NumSpokes:\InnerR) -- (\k*360/\NumSpokes:\OuterR+0.1) ;
}}}
\end{tikzpicture}
\end{document}