使用 tikz 绘制 3D 平面

使用 tikz 绘制 3D 平面

我想绘制一系列 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 包文档的源代码通常是公开的:

简而言之:我使用该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}

在此处输入图片描述

相关内容