I need to draw several similar shapes like this:
My code:
\documentclass[tikz,border=1mm]{standalone}
\usetikzlibrary{perspective}
\def\r{0.5}
\def\ri{\r*0.5}
\def\rii{\r*sqrt(2)/2}
\def\riii{\r*sqrt(3)/2}
\begin{document}
\begin{tikzpicture}[3d view={120}{20},fill=gray!20]
% box
\draw[fill] (1,0,0) -- (0,0,0)-- (0,0,1) -- (1,0,1) -- cycle;
\draw[fill] (0,0,0) -- (0,1,0)-- (0,1,1) -- (0,0,1) -- cycle;
\draw[fill] (1,0,0) -- (1,1,0)-- (1,1,1) -- (1,0,1) -- cycle;
\draw[fill] (1,1,0) -- (0,1,0)-- (0,1,1) -- (1,1,1) -- cycle;
% flaps
\draw[fill] (1,0,1) -- ({1+\rii},0,{1-\rii}) -- ({1+\rii},1,{1-\rii}) -- (1,1,1) -- cycle;
\draw[fill] (0,0,1) -- ({0-\rii},0,{1+\rii}) -- ({0-\rii},1,{1+\rii}) -- (0,1,1) -- cycle;
\draw[fill] (1,1,1) -- (1,{1+\ri},{1-\riii}) -- (0,{1+\ri},{1-\riii}) -- (0,1,1) -- cycle;
\draw[fill] (1,0,1) -- (1,{0-\ri},{1+\riii}) -- (0,{0-\ri},{1+\riii}) -- (0,0,1) -- cycle;
\end{tikzpicture}
\end{document}
I'm wondering if there is another better way to achieve this, by using simpler or more readable code. In particular:
- Is there any path command like the 2d 'rectangle' to use on a 3d picture? It would be desirable.
- Is there another way to deal with coordinates to avoid redundant information?
Any improvement will be welcome.
canvas is xy plane at z=1
See: tex.stackexchange.com/a/629795/8650