我正在尝试绘制 3D 中的矩形,但我编写的以下代码给出了意外的结果:
\documentclass{minimal}
\usepackage{tikz,tikz-3dplot}
\begin{document}
\begin{tikzpicture}[baseline,x=1cm,y=1cm,z=1cm]
\tdplotsetmaincoords{75}{110}
\begin{scope}[tdplot_main_coords]
\draw [blue](0,0,0) rectangle (3,3,0);
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\end{scope}
\end{tikzpicture}
\end{document}
不知何故,似乎 tdplot_main_coords 对矩形不起作用(但它对轴箭头起作用)。
答案1
矩形在二维中由两个对角唯一定义,但在三维中并非如此。如果切换到相关平面,则会得到一个变换后的矩形。这可以方便地使用 库来完成3d
,该库由 加载tikz-3dplot
。
\documentclass[tikz,border=1cm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\begin{tikzpicture}[baseline,x=1cm,y=1cm,z=1cm]
\tdplotsetmaincoords{75}{110}
\begin{scope}[tdplot_main_coords]
\begin{scope}[canvas is xy plane at z=0]
\draw [blue](0,0) rectangle (3,3);
\end{scope}
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\end{scope}
\end{tikzpicture}
\end{document}