大家好,我正在尝试用不同的方式绘制一个非常简单的立方体,但有些事情困扰着我,为什么顶点如此不完美?
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0,0) -- (0,1,0) -- (0,1,1) -- (1,1,1) -- (1,1,0) -- (1,0,0) -- (0,0,0) -- (0,0,1) -- (1,0,1) -- (1,0,0);
\draw (0,1,0) -- (1,1,0);
\draw (1,0,1) -- (1,1,1);
\draw (0,0,1) -- (0,1,1);
\end{tikzpicture}
\end{document}
答案1
你可以尝试这个代码
\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz,tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{120}
\begin{tikzpicture}[tdplot_main_coords,line cap=butt,line join=round,c/.style={circle,fill,inner sep=1pt},
declare function={a=2;}]
\path
(a,-a,-a) coordinate (A)
(a,a,-a) coordinate (B)
(-a,a,-a) coordinate (C)
(-a,-a,-a) coordinate (D)
(a,-a,a) coordinate (E)
(a,a,a) coordinate (F)
(-a,a,a) coordinate (G)
(-a,-a,a) coordinate (H)
(0,0,0) coordinate (O)
;
\draw[dashed] (D) -- (H) (D) -- (A) (D) -- (C);
\draw (H) -- (E) -- (F) -- (G) -- cycle (A) -- (E) (B) -- (F) (C) -- (G) (A) -- (B) -- (C);
\path foreach \p/\g in {A/-90,B/-90,C/-90,D/-90,E/90,F/90,G/90,H/90}{(\p)node[c]{}+(\g:2.5mm) node{$\p$}};
\end{tikzpicture}
\end{document}
120
您可以更改行中的数字\tdplotsetmaincoords{70}{120}
以获取另一种视图。
答案2
这非常简单 pstricks
– 更准确地说是pst-solides3d
:
\documentclass[border=6pt, pstricks, svgnames]{standalone}
\usepackage{pst-solides3d}
\begin{document}
\begin{pspicture*}(-10,-6 )(10,12)
\axesIIID[arrows=->, arrowsize=5pt, arrowinset=0.1, axisnames={x, y, z}](4,4,4)
\psSolid[object=cube, a=2, action =draw*, fillcolor=Lavender]
\end{pspicture*}
\end{document}