在平面上画一个时钟表

在平面上画一个时钟表

受到这个问题的启发,@Schrödinger's cat 的回答,如何有效地在平面上画出时钟表?

答案1

这只是一个嵌套循环。

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
 \foreach \X in {1,...,5}
 {\foreach \Y in {1,2,3}
 {\draw (\X,\Y) circle[radius=4mm]
 (\X,\Y) -- ++(180-45*\X:0.4);
 }}
\end{tikzpicture}
\end{document}

在此处输入图片描述

但我们可以做得更好一些现有的帖子

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{3d,decorations.markings}
\tikzset{Annie/.cd,
hour/.initial=0,
hour arm/.style={thick,shorten >=1mm,red},
clock/.style={semithick,fill=white},
clock radius/.initial=5mm}
\begin{document}
\tdplotsetmaincoords{60}{20} 
\begin{tikzpicture}[tdplot_main_coords,pics/clock/.style={code={
\tikzset{Annie/.cd,#1}
\draw[Annie/clock] (0,0) 
circle[radius=\pgfkeysvalueof{/tikz/Annie/clock radius}];
\draw[Annie/hour arm] (0,0) --
(90-30*\pgfkeysvalueof{/tikz/Annie/hour}:\pgfkeysvalueof{/tikz/Annie/clock radius});
}},ruler/.style={postaction={decorate,decoration={markings,
mark=between positions 0 and 1 step 5pt with {\draw (0,-#1/2) -- (0,#1/2);}}}}] 
\begin{scope}[canvas is xz plane at y=0,transform shape]
 \draw[double=cyan,double distance=4pt,ruler=4pt] (-4,-2.4) grid[step=pi/2] (4,4);
 \path foreach \X in {-2,...,2} 
  {foreach \Y in {-1,...,2} 
  { (\X*pi/2,\Y*pi/2) pic{clock={hour=\X*3/2}}}};
\end{scope} 
\end{tikzpicture}
\end{document}

在此处输入图片描述

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot} 
\usetikzlibrary{3d,decorations.markings}
\tikzset{Annie/.cd,
hour/.initial=0,
hour arm/.style={thick,shorten >=1mm,red},
clock/.style={semithick,fill=white},
clock radius/.initial=5mm}
\begin{document}
\tdplotsetmaincoords{60}{00} 
\begin{tikzpicture}[tdplot_main_coords,pics/clock/.style={code={
\tikzset{Annie/.cd,#1}
\draw[Annie/clock] (0,0) 
circle[radius=\pgfkeysvalueof{/tikz/Annie/clock radius}];
\draw[Annie/hour arm] (0,0) --
(90-30*\pgfkeysvalueof{/tikz/Annie/hour}:\pgfkeysvalueof{/tikz/Annie/clock radius});
}},ruler/.style={postaction={decorate,decoration={markings,
mark=between positions 0 and 1 step 5pt with {\draw (0,-#1/2) -- (0,#1/2);}}}}] 
\begin{scope}[canvas is xz plane at y=0,transform shape]
 \draw[double=cyan,double distance=4pt,ruler=4pt] (-4,-2.4) grid[step=pi/2] (6,4);
 \path foreach \X in {-2,...,3} 
  {foreach \Y in {-1,...,2} 
  { (\X*pi/2,\Y*pi/2) pic{clock={hour=\X*3/2}}}};
\end{scope} 
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容