答案1
给你一个开始。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{perspective}
\begin{document}
\begin{tikzpicture}[3d view={30}{15},line cap=round,
declare function={ax=2;ay=1.5;az=2.5;bx=0.5;bz=0.5;}]
\draw (0,0,0) -- (ax,0,0) -- (ax,0,bz) -- (bx,0,bz) -- (bx,0,az)
-- (0,0,az) -- cycle
(0,0,az) -- (0,ay,az) -- (bx,ay,az) edge ++ (0,-ay,0)
-- (bx,ay,az) edge ++ (0,-ay,0)
-- (bx,ay,bz) edge ++ (0,-ay,0)
-- (ax,ay,bz) edge ++ (0,-ay,0)
-- (ax,ay,0) -- (ax,0,0);
\end{tikzpicture}
\end{document}
该perspective
库允许我们改变视角,并declare function
用于定义可以改变的参数。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{perspective}
\begin{document}
\begin{tikzpicture}[3d view={40}{35},line cap=round,
declare function={ax=3;ay=2;az=2.5;bx=0.8;bz=0.8;}]
\draw (0,0,0) -- (ax,0,0) -- (ax,0,bz) -- (bx,0,bz) -- (bx,0,az)
-- (0,0,az) -- cycle
(0,0,az) -- (0,ay,az) -- (bx,ay,az) edge ++ (0,-ay,0)
-- (bx,ay,az) edge ++ (0,-ay,0)
-- (bx,ay,bz) edge ++ (0,-ay,0)
-- (ax,ay,bz) edge ++ (0,-ay,0)
-- (ax,ay,0) -- (ax,0,0);
\end{tikzpicture}
\end{document}
答案2
我建议使用下面的代码。这是因为我喜欢它的可读性,而且它可以快速编写...
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,3d}
\begin{document}
\begin{tikzpicture}[x = {(0.95cm,-0.3cm)},
y = {(0.707cm,0.707cm)},
z = {(0cm,1cm)}]
\begin{scope}[canvas is zx plane at y=0]
\draw (0,0) -- ++(3,0) -- ++(0,1) --++(-2,0) -- ++(0,5) -- ++(-1,0) -- (0,0);
\end{scope}
\begin{scope}[canvas is zy plane at x=0]
\draw (3,0) -- ++(0,3);
\end{scope}
\begin{scope}[canvas is zy plane at x=1]
\draw (3,0) -- ++(0,3);
\draw (1,0) -- ++(0,3);
\end{scope}
\begin{scope}[canvas is zy plane at x=6]
\draw (0,0) -- ++(0,3);
\draw (1,0) -- ++(0,3);
\end{scope}
\begin{scope}[canvas is zx plane at y=3]
\draw (0,0) ++(3,0) -- ++(0,1) --++(-2,0) -- ++(0,5) -- ++(-1,0);
\end{scope}
\end{tikzpicture}
\end{document}