7

I want to draw a series of planes in 3D, just like a picture in tikz-ducks documentation: enter image description here

I thought it might be easy but I was stuck at drawing the planes in 3D. My own code:

\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}

which produces:

enter image description here

I experimented a lot but I couldn't figure out how to set these 3D coordinates. How could I draw a blue rectangle as shown in the example? Additionally how could I rotate a picture in the same way?

6
  • 2
  • 1
    You want something like \draw (0,0,0) -- (0,0,1) -- (0,1,1) -- (0,1,0) -- cycle;. In the squares in the picture you show, the x value never changes as the squares are in the yz plane (up-down and front-back). Commented Dec 13, 2023 at 12:15
  • @samcarter_is_at_topanswers.xyz wow, thanks for the source code! Commented Dec 13, 2023 at 12:17
  • @JasperHabicht Right, I was confused, but now I somehow get it Commented Dec 13, 2023 at 12:17
  • 2
    shame, I saw the title and thought you wanted this Commented Dec 13, 2023 at 13:11

1 Answer 1

9

The source code of latex package documentations is normally publicly available:

In short: I used the 3d library for this image:

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .