在三维立方体上创建表盘

在三维立方体上创建表盘

我想在这个盒子的顶部画一个表盘,就像这张图片一样。到目前为止,我已经使用了 tikz。这可能吗?

在此处输入图片描述

在此处输入图片描述

代码示例

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[y={(-1cm,0.5cm)},x={(1cm,0.5cm)}, z={(0cm,1cm)}]
\pgfmathsetmacro{\cubex}{4}
\pgfmathsetmacro{\cubey}{5}
\pgfmathsetmacro{\cubez}{3}
\draw [fill=gray!50] (0,0,0)--++(\cubex,0,0)--++(0,\cubey,0)--++(-\cubex,0,0)--(0,0,0)--++(0,0,-\cubez)--++(0,\cubey,0)--++(0,0,\cubez)--(0,0,0)--++(\cubex,0,0)--++(0,0,-\cubez)--++(-\cubex,0,0)--(0,0,0);
\end{tikzpicture}
\end{document}

答案1

使用 3D 库相当简单。烹饪愉快!

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{3d,shapes.geometric}
\begin{document}
\begin{tikzpicture}[y={(1cm,-0.5cm)},x={(1cm,0.5cm)}, z={(0cm,1cm)}]
\pgfmathsetmacro{\cubex}{4}
\pgfmathsetmacro{\cubey}{5}
\pgfmathsetmacro{\cubez}{3}
\draw [fill=gray!50] (0,0,0)--++(\cubex,0,0)--++(0,-\cubey,0)--++(-\cubex,0,0)--(0,0,0)--++(0,0,-\cubez)--++(0,-\cubey,0)--++(0,0,\cubez)--(0,0,0)--++(\cubex,0,0)--++(0,0,-\cubez)--++(-\cubex,0,0)--(0,0,0);

\begin{scope}[canvas is yx plane at z=0,transform shape]
\draw[ultra thick] (-\cubex/2,\cubey/3) circle(1cm);
\node [regular polygon, minimum size=2cm, regular polygon sides=18] 
(lower poly) at (-\cubex/2,\cubey/3) {};
\node [regular polygon, minimum size=2.6cm, regular polygon sides=18] 
(label poly) at (-\cubex/2,\cubey/3) {};
\foreach \X [evaluate=\X as \Y using int(18-\X)]in {1,...,11}
{\node at (label poly.corner \Y) {\X};}
\end{scope}
\begin{scope}[canvas is yx plane at z=2,transform shape]
\node [regular polygon, minimum size=1.6cm, regular polygon sides=18] 
(upper poly) at (-\cubex/2,\cubey/3) {};
\end{scope}
\foreach \X [evaluate=\X as \Y using int(18-\X)]in {1,...,10}
{
\pgfmathtruncatemacro{\Z}{\Y-1}
\ifnum\Y=8
\else
\fill[white] (lower poly.corner \Y) -- (upper poly.corner \Y) --
(upper poly.corner \Z) -- (lower poly.corner \Z) -- cycle;
\fi
\draw[ultra thick] (lower poly.corner \Y) -- (upper poly.corner \Y);}
\begin{scope}[canvas is yx plane at z=2,transform shape]
\draw[ultra thick,fill=white] (-\cubex/2,\cubey/3) circle(0.8cm);
\end{scope}
\begin{scope}[canvas is yx plane at z=2.2,transform shape]
\draw[ultra thick,fill=white] (-\cubex/2,\cubey/3) circle(0.7cm);
\draw[ultra thick] (-\cubex/2,\cubey/3) -- ++ (220:0.7cm);
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容