借助于 TikZ
提供的 calc
库,只需要一个顶点及其相邻的三个顶点的坐标即可画出一般的平行六面体,取特殊的点而得长方体或者正方体. 以下是一个 MWE:
\documentclass{standalone}
\usepackage{tikz}%%,pgfplots
\usetikzlibrary{3d,calc}%%,intersections
\tikzset{otmm/.style={x={(-135:0.5cm)},y={(0:1cm)},z={(90:1cm)}}}
%一般情况下只需要修改 A C D1 坐标即可得到正方体或长方体
\begin{document}
\begin{tikzpicture}[otmm]
\coordinate [label=left:$D$] (D) at (0,0,0);
\coordinate [label=left:$A$] (A) at (2,-1,0);
\coordinate [label=right:$C$] (C) at (0,3,0);
\coordinate [label=left:$D_1$] (D1) at (-1,1,2);
\coordinate[label=below:$B$] (B) at ($(A)+(C)-2*(D)$);
\coordinate[label=left:$A_1$] (A1) at ($(A)+(D1)-(D)$);
\coordinate[label=above:$B_1$] (B1) at ($(B)+(D1)-(D)$);
\coordinate[label=right:$C_1$] (C1) at ($(C)+(D1)-(D)$);
\draw [dashed] (D) -- (A) (D) -- (C) (D) -- (D1);
\draw (B) -- (B1) -- (A1) -- (A) -- cycle -- (C) -- (C1) -- (D1) -- (A1)
(B1) -- (C1);
\end{tikzpicture}
\end{document}