我想绘制一系列 3D 平面,就像 tikz-ducks 文档中的图片一样:
我以为这可能很容易,但我却无法在 3D 中绘制平面。我自己的代码:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\filldraw[
draw=red,%
fill=red!20,%
] (0,0,0)
-- (3,1,0)
-- (3,1,3)
-- (1,0,3)
-- cycle;
\end{tikzpicture}
\end{document}
生成结果:
我做了很多实验,但就是搞不清楚如何设置这些 3D 坐标。如何绘制如示例中所示的蓝色矩形?此外,如何以同样的方式旋转图片?
答案1
latex 包文档的源代码通常是公开的:
正切:http://mirrors.ctan.org/graphics/pgf/contrib/tikzducks/tikzducks-doc.tex
甚至可能安装在你的电脑上,查看你
texdoc -l tikzducks
在命令行上运行得到的文件夹对于 TikZducks 包,也可以从以下位置获取源代码:https://github.com/samcarter/tikzducks/blob/main/tikzducks-doc.tex#L1061-L1108
简而言之:我使用该3d
库来获取此图像:
\documentclass{standalone}
\usepackage{tikzducks}
\usetikzlibrary{3d}
\begin{document}
\begin{tikzpicture}
\newcommand{\planes}{\fill[gray!20!white,opacity=0.9] (-0.1,-0.1) rectangle (2.4,2.4);}
\newcommand{\hooks}{\draw[blue, rounded corners=3pt, line width=1pt] (-0.1,-0.1) rectangle (2.4,2.4);}
\node[font=\footnotesize\ttfamily] at (-0.8,-1.4) {\strut background};
\begin{scope}[canvas is zy plane at x=0]
\hooks
\end{scope}
\begin{scope}[canvas is zy plane at x=0.8]
\planes
\duck
\end{scope}
\node[font=\footnotesize\ttfamily] at (0.8,-1.4) {\strut body};
\begin{scope}[canvas is zy plane at x=1.6]
\hooks
\end{scope}
\begin{scope}[canvas is zy plane at x=2.4]
\planes
\duck[invisible,jacket=black!50!gray]
\end{scope}
\node[font=\footnotesize\ttfamily] at (2.4,-1.4) {\strut clothing};
\begin{scope}[canvas is zy plane at x=3.2]
\hooks
\end{scope}
\begin{scope}[canvas is zy plane at x=4.0]
\planes
\duck[invisible,longhair=red!80!black]
\end{scope}
\node[font=\footnotesize\ttfamily] at (4.0,-1.4) {\strut hair};
\begin{scope}[canvas is zy plane at x=4.8]
\hooks
\end{scope}
\begin{scope}[canvas is zy plane at x=5.6]
\planes
\duck[invisible,witch=black!50!gray];
\end{scope}
\node[font=\footnotesize\ttfamily] at (5.6,-1.4) {\strut hat};
\begin{scope}[canvas is zy plane at x=6.4]
\hooks
\end{scope}
\begin{scope}[canvas is zy plane at x=7.2]
\planes
\duck[invisible,magicwand]
\end{scope}
\node[font=\footnotesize\ttfamily] at (7.2,-1.4) {\strut foreground};
\begin{scope}[canvas is zy plane at x=8.0]
\hooks
\end{scope}
\end{tikzpicture}
\end{document}