我想绘制块(运输托盘)。每个块宽 0.8m,深 1.2m,高 2.15m,水平放置(只有一个块高度),分组为 2x2、3x3、4x4、5x5、6x6、7x7 块。
我一直在测试两种解决方案“需要帮助从 TikZ 中的一组 2D 节点创建 3D 立方体”但我不知道如何使代码适应我的问题。
例如,我想更改此示例的长方体尺寸:
\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm,landscape]{geometry}
\usepackage{tikz}
\newif\ifcuboidshade
\newif\ifcuboidemphedge
\tikzset{
cuboid/.is family,
cuboid,
shiftx/.initial=0,
shifty/.initial=0,
dimx/.initial=3,
dimy/.initial=3,
dimz/.initial=3,
scale/.initial=1,
densityx/.initial=1,
densityy/.initial=1,
densityz/.initial=1,
rotation/.initial=0,
anglex/.initial=0,
angley/.initial=90,
anglez/.initial=225,
scalex/.initial=1,
scaley/.initial=1,
scalez/.initial=0.5,
front/.style={draw=black,fill=white},
top/.style={draw=black,fill=white},
right/.style={draw=black,fill=white},
shade/.is if=cuboidshade,
shadecolordark/.initial=black,
shadecolorlight/.initial=white,
shadeopacity/.initial=0.15,
shadesamples/.initial=16,
emphedge/.is if=cuboidemphedge,
emphstyle/.style={thick},
}
\newcommand{\tikzcuboidkey}[1]{\pgfkeysvalueof{/tikz/cuboid/#1}}
% Commands
\newcommand{\tikzcuboid}[1]{
\tikzset{cuboid,#1} % Process Keys passed to command
\pgfmathsetlengthmacro{\vectorxx}{\tikzcuboidkey{scalex}*cos(\tikzcuboidkey{anglex})*28.452756}
\pgfmathsetlengthmacro{\vectorxy}{\tikzcuboidkey{scalex}*sin(\tikzcuboidkey{anglex})*28.452756}
\pgfmathsetlengthmacro{\vectoryx}{\tikzcuboidkey{scaley}*cos(\tikzcuboidkey{angley})*28.452756}
\pgfmathsetlengthmacro{\vectoryy}{\tikzcuboidkey{scaley}*sin(\tikzcuboidkey{angley})*28.452756}
\pgfmathsetlengthmacro{\vectorzx}{\tikzcuboidkey{scalez}*cos(\tikzcuboidkey{anglez})*28.452756}
\pgfmathsetlengthmacro{\vectorzy}{\tikzcuboidkey{scalez}*sin(\tikzcuboidkey{anglez})*28.452756}
\begin{scope}[xshift=\tikzcuboidkey{shiftx}, yshift=\tikzcuboidkey{shifty}, scale=\tikzcuboidkey{scale}, rotate=\tikzcuboidkey{rotation}, x={(\vectorxx,\vectorxy)}, y={(\vectoryx,\vectoryy)}, z={(\vectorzx,\vectorzy)}]
\pgfmathsetmacro{\steppingx}{1/\tikzcuboidkey{densityx}}
\pgfmathsetmacro{\steppingy}{1/\tikzcuboidkey{densityy}}
\pgfmathsetmacro{\steppingz}{1/\tikzcuboidkey{densityz}}
\newcommand{\dimx}{\tikzcuboidkey{dimx}}
\newcommand{\dimy}{\tikzcuboidkey{dimy}}
\newcommand{\dimz}{\tikzcuboidkey{dimz}}
\pgfmathsetmacro{\secondx}{2*\steppingx}
\pgfmathsetmacro{\secondy}{2*\steppingy}
\pgfmathsetmacro{\secondz}{2*\steppingz}
\foreach \x in {\steppingx,\secondx,...,\dimx}
{ \foreach \y in {\steppingy,\secondy,...,\dimy}
{ \pgfmathsetmacro{\lowx}{(\x-\steppingx)}
\pgfmathsetmacro{\lowy}{(\y-\steppingy)}
\filldraw[cuboid/front] (\lowx,\lowy,\dimz) -- (\lowx,\y,\dimz) -- (\x,\y,\dimz) -- (\x,\lowy,\dimz) -- cycle;
}
}
\foreach \x in {\steppingx,\secondx,...,\dimx}
{ \foreach \z in {\steppingz,\secondz,...,\dimz}
{ \pgfmathsetmacro{\lowx}{(\x-\steppingx)}
\pgfmathsetmacro{\lowz}{(\z-\steppingz)}
\filldraw[cuboid/top] (\lowx,\dimy,\lowz) -- (\lowx,\dimy,\z) -- (\x,\dimy,\z) -- (\x,\dimy,\lowz) -- cycle;
}
}
\foreach \y in {\steppingy,\secondy,...,\dimy}
{ \foreach \z in {\steppingz,\secondz,...,\dimz}
{ \pgfmathsetmacro{\lowy}{(\y-\steppingy)}
\pgfmathsetmacro{\lowz}{(\z-\steppingz)}
\filldraw[cuboid/right] (\dimx,\lowy,\lowz) -- (\dimx,\lowy,\z) -- (\dimx,\y,\z) -- (\dimx,\y,\lowz) -- cycle;
}
}
\ifcuboidemphedge
\draw[cuboid/emphstyle] (0,\dimy,0) -- (\dimx,\dimy,0) -- (\dimx,\dimy,\dimz) -- (0,\dimy,\dimz) -- cycle;%
\draw[cuboid/emphstyle] (0,\dimy,\dimz) -- (0,0,\dimz) -- (\dimx,0,\dimz) -- (\dimx,\dimy,\dimz);%
\draw[cuboid/emphstyle] (\dimx,\dimy,0) -- (\dimx,0,0) -- (\dimx,0,\dimz);%
\fi
\ifcuboidshade
\pgfmathsetmacro{\cstepx}{\dimx/\tikzcuboidkey{shadesamples}}
\pgfmathsetmacro{\cstepy}{\dimy/\tikzcuboidkey{shadesamples}}
\pgfmathsetmacro{\cstepz}{\dimz/\tikzcuboidkey{shadesamples}}
\foreach \s in {1,...,\tikzcuboidkey{shadesamples}}
{ \pgfmathsetmacro{\lows}{\s-1}
\pgfmathsetmacro{\cpercent}{(\lows)/(\tikzcuboidkey{shadesamples}-1)*100}
\fill[opacity=\tikzcuboidkey{shadeopacity},color=\tikzcuboidkey{shadecolorlight}!\cpercent!\tikzcuboidkey{shadecolordark}] (0,\s*\cstepy,\dimz) -- (\s*\cstepx,\s*\cstepy,\dimz) -- (\s*\cstepx,0,\dimz) -- (\lows*\cstepx,0,\dimz) -- (\lows*\cstepx,\lows*\cstepy,\dimz) -- (0,\lows*\cstepy,\dimz) -- cycle;
\fill[opacity=\tikzcuboidkey{shadeopacity},color=\tikzcuboidkey{shadecolorlight}!\cpercent!\tikzcuboidkey{shadecolordark}] (0,\dimy,\s*\cstepz) -- (\s*\cstepx,\dimy,\s*\cstepz) -- (\s*\cstepx,\dimy,0) -- (\lows*\cstepx,\dimy,0) -- (\lows*\cstepx,\dimy,\lows*\cstepz) -- (0,\dimy,\lows*\cstepz) -- cycle;
\fill[opacity=\tikzcuboidkey{shadeopacity},color=\tikzcuboidkey{shadecolorlight}!\cpercent!\tikzcuboidkey{shadecolordark}] (\dimx,0,\s*\cstepz) -- (\dimx,\s*\cstepy,\s*\cstepz) -- (\dimx,\s*\cstepy,0) -- (\dimx,\lows*\cstepy,0) -- (\dimx,\lows*\cstepy,\lows*\cstepz) -- (\dimx,0,\lows*\cstepz) -- cycle;
}
\fi
\end{scope}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\tikzcuboid{%
shiftx=0cm,%
shifty=0cm,%
scale=1.00,%
rotation=0,%
densityx=1,%
densityy=1,%
densityz=1,%
dimx=4,%
dimy=2,%
dimz=4,%
front/.style={draw=blue!75!black,fill=blue!25!white},%
right/.style={draw=blue!25!black,fill=blue!75!white},%
top/.style={draw=blue!50!black,fill=blue!50!white},%
anglex=-7,%
angley=90,%
anglez=221.5,%
scalex=1,%
scaley=1,%
scalez=0.5,%
emphedge=false,%
shade,%
shadeopacity=0.15,%
}
\end{tikzpicture}
\end{document}
当我只想绘制 1 层时,它有 2 层块,并且立方体的 xyz 尺寸相同,我想更改长方体的 x、y 和 z 尺寸。
我也测试了第二种解决方案,但仍然无法得到我想要的结果。
如果可能的话,我还想在 x、y 和 z 维度上放置一个标签,其中标明每组块的总尺寸。我不知道标签的文本是否可以与图形的相同侧角对齐。例如,对于 2x2 组块,x 维度为 1.6m,y 维度为 2.15 m(只有一层块),z 维度为 2.4m。
编辑
使用下面的 marmot 解决方案,并且
scalex=0.8,%
scaley=2.0,%
scalez=0.5,%
我想放置具有组各边尺寸的文本。例如:
答案1
我猜你使用的代码没有预见到在给定方向上只有一个立方体。为了解决这个问题,我替换了
\foreach \x in {\steppingx,\secondx,...,\dimx}
经过
\ifnum\dimx=1
\def\lstx{\dimx}
\else
\def\lstx{\steppingx,\secondx,...,\dimx}
\fi
\foreach \x in \lstx
其他方向也类似。除此之外,各个方向的尺寸由 等键设置,我在 MWE 中将scalex
其设置为2
\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm,landscape]{geometry}
\usepackage{tikz}
\newif\ifcuboidshade
\newif\ifcuboidemphedge
\tikzset{
cuboid/.is family,
cuboid,
shiftx/.initial=0,
shifty/.initial=0,
dimx/.initial=3,
dimy/.initial=3,
dimz/.initial=3,
scale/.initial=1,
densityx/.initial=1,
densityy/.initial=1,
densityz/.initial=1,
rotation/.initial=0,
anglex/.initial=0,
angley/.initial=90,
anglez/.initial=225,
scalex/.initial=1,
scaley/.initial=1,
scalez/.initial=0.5,
front/.style={draw=black,fill=white},
top/.style={draw=black,fill=white},
right/.style={draw=black,fill=white},
shade/.is if=cuboidshade,
shadecolordark/.initial=black,
shadecolorlight/.initial=white,
shadeopacity/.initial=0.15,
shadesamples/.initial=16,
emphedge/.is if=cuboidemphedge,
emphstyle/.style={thick},
}
\newcommand{\tikzcuboidkey}[1]{\pgfkeysvalueof{/tikz/cuboid/#1}}
% Commands
\newcommand{\tikzcuboid}[1]{
\tikzset{cuboid,#1} % Process Keys passed to command
\pgfmathsetlengthmacro{\vectorxx}{\tikzcuboidkey{scalex}*cos(\tikzcuboidkey{anglex})*28.452756}
\pgfmathsetlengthmacro{\vectorxy}{\tikzcuboidkey{scalex}*sin(\tikzcuboidkey{anglex})*28.452756}
\pgfmathsetlengthmacro{\vectoryx}{\tikzcuboidkey{scaley}*cos(\tikzcuboidkey{angley})*28.452756}
\pgfmathsetlengthmacro{\vectoryy}{\tikzcuboidkey{scaley}*sin(\tikzcuboidkey{angley})*28.452756}
\pgfmathsetlengthmacro{\vectorzx}{\tikzcuboidkey{scalez}*cos(\tikzcuboidkey{anglez})*28.452756}
\pgfmathsetlengthmacro{\vectorzy}{\tikzcuboidkey{scalez}*sin(\tikzcuboidkey{anglez})*28.452756}
\begin{scope}[xshift=\tikzcuboidkey{shiftx}, yshift=\tikzcuboidkey{shifty}, scale=\tikzcuboidkey{scale}, rotate=\tikzcuboidkey{rotation}, x={(\vectorxx,\vectorxy)}, y={(\vectoryx,\vectoryy)}, z={(\vectorzx,\vectorzy)}]
\pgfmathsetmacro{\steppingx}{1/\tikzcuboidkey{densityx}}
\pgfmathsetmacro{\steppingy}{1/\tikzcuboidkey{densityy}}
\pgfmathsetmacro{\steppingz}{1/\tikzcuboidkey{densityz}}
\newcommand{\dimx}{\tikzcuboidkey{dimx}}
\newcommand{\dimy}{\tikzcuboidkey{dimy}}
\newcommand{\dimz}{\tikzcuboidkey{dimz}}
\pgfmathsetmacro{\secondx}{2*\steppingx}
\pgfmathsetmacro{\secondy}{2*\steppingy}
\pgfmathsetmacro{\secondz}{2*\steppingz}
\foreach \x in {\steppingx,\secondx,...,\dimx}
{\ifnum\dimy=1
\def\lsty{\dimy}
\else
\def\lsty{\steppingy,\secondy,...,\dimy}
\fi
\foreach \y in \lsty
{ \pgfmathsetmacro{\lowx}{(\x-\steppingx)}
\pgfmathsetmacro{\lowy}{(\y-\steppingy)}
\filldraw[cuboid/front] (\lowx,\lowy,\dimz) -- (\lowx,\y,\dimz) -- (\x,\y,\dimz) -- (\x,\lowy,\dimz) -- cycle;
}
}
\ifnum\dimx=1
\def\lstx{\dimx}
\else
\def\lstx{\steppingx,\secondx,...,\dimx}
\fi
\foreach \x in \lstx
{ \ifnum\dimz=1
\def\lstz{\dimz}
\else
\def\lstz{\steppingz,\secondz,...,\dimz}
\fi
\foreach \z in \lstz
{ \pgfmathsetmacro{\lowx}{(\x-\steppingx)}
\pgfmathsetmacro{\lowz}{(\z-\steppingz)}
\filldraw[cuboid/top] (\lowx,\dimy,\lowz) -- (\lowx,\dimy,\z) -- (\x,\dimy,\z) -- (\x,\dimy,\lowz) -- cycle;
}
}
\ifnum\dimy=1
\def\lsty{\dimy}
\else
\def\lsty{\steppingy,\secondy,...,\dimy}
\fi
\foreach \y in \lsty
{ \foreach \z in {\steppingz,\secondz,...,\dimz}
{ \pgfmathsetmacro{\lowy}{(\y-\steppingy)}
\pgfmathsetmacro{\lowz}{(\z-\steppingz)}
\filldraw[cuboid/right] (\dimx,\lowy,\lowz) -- (\dimx,\lowy,\z) -- (\dimx,\y,\z) -- (\dimx,\y,\lowz) -- cycle;
}
}
\ifcuboidemphedge
\draw[cuboid/emphstyle] (0,\dimy,0) -- (\dimx,\dimy,0) -- (\dimx,\dimy,\dimz) -- (0,\dimy,\dimz) -- cycle;%
\draw[cuboid/emphstyle] (0,\dimy,\dimz) -- (0,0,\dimz) -- (\dimx,0,\dimz) -- (\dimx,\dimy,\dimz);%
\draw[cuboid/emphstyle] (\dimx,\dimy,0) -- (\dimx,0,0) -- (\dimx,0,\dimz);%
\fi
\ifcuboidshade
\pgfmathsetmacro{\cstepx}{\dimx/\tikzcuboidkey{shadesamples}}
\pgfmathsetmacro{\cstepy}{\dimy/\tikzcuboidkey{shadesamples}}
\pgfmathsetmacro{\cstepz}{\dimz/\tikzcuboidkey{shadesamples}}
\foreach \s in {1,...,\tikzcuboidkey{shadesamples}}
{ \pgfmathsetmacro{\lows}{\s-1}
\pgfmathsetmacro{\cpercent}{(\lows)/(\tikzcuboidkey{shadesamples}-1)*100}
\fill[opacity=\tikzcuboidkey{shadeopacity},color=\tikzcuboidkey{shadecolorlight}!\cpercent!\tikzcuboidkey{shadecolordark}] (0,\s*\cstepy,\dimz) -- (\s*\cstepx,\s*\cstepy,\dimz) -- (\s*\cstepx,0,\dimz) -- (\lows*\cstepx,0,\dimz) -- (\lows*\cstepx,\lows*\cstepy,\dimz) -- (0,\lows*\cstepy,\dimz) -- cycle;
\fill[opacity=\tikzcuboidkey{shadeopacity},color=\tikzcuboidkey{shadecolorlight}!\cpercent!\tikzcuboidkey{shadecolordark}] (0,\dimy,\s*\cstepz) -- (\s*\cstepx,\dimy,\s*\cstepz) -- (\s*\cstepx,\dimy,0) -- (\lows*\cstepx,\dimy,0) -- (\lows*\cstepx,\dimy,\lows*\cstepz) -- (0,\dimy,\lows*\cstepz) -- cycle;
\fill[opacity=\tikzcuboidkey{shadeopacity},color=\tikzcuboidkey{shadecolorlight}!\cpercent!\tikzcuboidkey{shadecolordark}] (\dimx,0,\s*\cstepz) -- (\dimx,\s*\cstepy,\s*\cstepz) -- (\dimx,\s*\cstepy,0) -- (\dimx,\lows*\cstepy,0) -- (\dimx,\lows*\cstepy,\lows*\cstepz) -- (\dimx,0,\lows*\cstepz) -- cycle;
}
\fi
\end{scope}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\tikzcuboid{%
shiftx=0cm,%
shifty=0cm,%
scale=1.00,%
rotation=0,%
densityx=1,%
densityy=1,%
densityz=1,%
dimx=4,%
dimy=1,%
dimz=4,%
front/.style={draw=blue!75!black,fill=blue!25!white},%
right/.style={draw=blue!25!black,fill=blue!75!white},%
top/.style={draw=blue!50!black,fill=blue!50!white},%
anglex=-7,%
angley=90,%
anglez=221.5,%
scalex=2,%
scaley=1,%
scalez=0.5,%
emphedge=false,%
shade,%
shadeopacity=0.15,%
}
\end{tikzpicture}
\end{document}
更新:我为 egde 标签添加了一些键。但请注意,如果您使用(非常)不同的角度,它们可能看起来不太好。我也没有使用siunitx
排版距离(因为我不想用不直接相关的包淹没这个答案)。如果您想要一个标签在所有可能的角度看起来都很好的解决方案,请提出一个单独的问题。
\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm,landscape]{geometry}
\usepackage{tikz}
\newif\ifcuboidshade
\newif\ifcuboidemphedge
\tikzset{
cuboid/.is family,
cuboid,
shiftx/.initial=0,
shifty/.initial=0,
dimx/.initial=3,
dimy/.initial=3,
dimz/.initial=3,
scale/.initial=1,
densityx/.initial=1,
densityy/.initial=1,
densityz/.initial=1,
rotation/.initial=0,
anglex/.initial=0,
angley/.initial=90,
anglez/.initial=225,
scalex/.initial=1,
scaley/.initial=1,
scalez/.initial=0.5,
xedgelabel/.store in=\xedgelabel,
yedgelabel/.store in=\yedgelabel,
zedgelabel/.store in=\zedgelabel,
xedgelabel={},
yedgelabel={},
zedgelabel={},
edgelabel/.style={},
front/.style={draw=black,fill=white},
top/.style={draw=black,fill=white},
right/.style={draw=black,fill=white},
shade/.is if=cuboidshade,
shadecolordark/.initial=black,
shadecolorlight/.initial=white,
shadeopacity/.initial=0.15,
shadesamples/.initial=16,
emphedge/.is if=cuboidemphedge,
emphstyle/.style={thick},
}
\newcommand{\tikzcuboidkey}[1]{\pgfkeysvalueof{/tikz/cuboid/#1}}
% Commands
\newcommand{\tikzcuboid}[1]{
\tikzset{cuboid,#1} % Process Keys passed to command
\pgfmathsetlengthmacro{\vectorxx}{\tikzcuboidkey{scalex}*cos(\tikzcuboidkey{anglex})*28.452756}
\pgfmathsetlengthmacro{\vectorxy}{\tikzcuboidkey{scalex}*sin(\tikzcuboidkey{anglex})*28.452756}
\pgfmathsetlengthmacro{\vectoryx}{\tikzcuboidkey{scaley}*cos(\tikzcuboidkey{angley})*28.452756}
\pgfmathsetlengthmacro{\vectoryy}{\tikzcuboidkey{scaley}*sin(\tikzcuboidkey{angley})*28.452756}
\pgfmathsetlengthmacro{\vectorzx}{\tikzcuboidkey{scalez}*cos(\tikzcuboidkey{anglez})*28.452756}
\pgfmathsetlengthmacro{\vectorzy}{\tikzcuboidkey{scalez}*sin(\tikzcuboidkey{anglez})*28.452756}
\begin{scope}[xshift=\tikzcuboidkey{shiftx}, yshift=\tikzcuboidkey{shifty}, scale=\tikzcuboidkey{scale}, rotate=\tikzcuboidkey{rotation}, x={(\vectorxx,\vectorxy)}, y={(\vectoryx,\vectoryy)}, z={(\vectorzx,\vectorzy)}]
\pgfmathsetmacro{\steppingx}{1/\tikzcuboidkey{densityx}}
\pgfmathsetmacro{\steppingy}{1/\tikzcuboidkey{densityy}}
\pgfmathsetmacro{\steppingz}{1/\tikzcuboidkey{densityz}}
\newcommand{\dimx}{\tikzcuboidkey{dimx}}
\newcommand{\dimy}{\tikzcuboidkey{dimy}}
\newcommand{\dimz}{\tikzcuboidkey{dimz}}
\pgfmathsetmacro{\secondx}{2*\steppingx}
\pgfmathsetmacro{\secondy}{2*\steppingy}
\pgfmathsetmacro{\secondz}{2*\steppingz}
\foreach \x in {\steppingx,\secondx,...,\dimx}
{\ifnum\dimy=1
\def\lsty{\dimy}
\else
\def\lsty{\steppingy,\secondy,...,\dimy}
\fi
\foreach \y in \lsty
{ \pgfmathsetmacro{\lowx}{(\x-\steppingx)}
\pgfmathsetmacro{\lowy}{(\y-\steppingy)}
\filldraw[cuboid/front] (\lowx,\lowy,\dimz) -- (\lowx,\y,\dimz) -- (\x,\y,\dimz) -- (\x,\lowy,\dimz) -- cycle;
}
}
\ifnum\dimx=1
\def\lstx{\dimx}
\else
\def\lstx{\steppingx,\secondx,...,\dimx}
\fi
\foreach \x in \lstx
{ \ifnum\dimz=1
\def\lstz{\dimz}
\else
\def\lstz{\steppingz,\secondz,...,\dimz}
\fi
\foreach \z in \lstz
{ \pgfmathsetmacro{\lowx}{(\x-\steppingx)}
\pgfmathsetmacro{\lowz}{(\z-\steppingz)}
\filldraw[cuboid/top] (\lowx,\dimy,\lowz) -- (\lowx,\dimy,\z) -- (\x,\dimy,\z) -- (\x,\dimy,\lowz) -- cycle;
}
}
\ifnum\dimy=1
\def\lsty{\dimy}
\else
\def\lsty{\steppingy,\secondy,...,\dimy}
\fi
\foreach \y in \lsty
{ \foreach \z in {\steppingz,\secondz,...,\dimz}
{ \pgfmathsetmacro{\lowy}{(\y-\steppingy)}
\pgfmathsetmacro{\lowz}{(\z-\steppingz)}
\filldraw[cuboid/right] (\dimx,\lowy,\lowz) -- (\dimx,\lowy,\z) -- (\dimx,\y,\z) -- (\dimx,\y,\lowz) -- cycle;
}
}
\path (0,0,\dimz) -- (0,\dimy,\dimz) node[midway,above,edgelabel]{\yedgelabel};
\path (0,0,\dimz) -- (\dimx,0,\dimz) node[midway,below,edgelabel]{\xedgelabel};
\path (\dimx,0,\dimz) -- (\dimx,0,0) node[midway,below,edgelabel]{\zedgelabel};
\ifcuboidemphedge
\draw[cuboid/emphstyle] (0,\dimy,0) -- (\dimx,\dimy,0) -- (\dimx,\dimy,\dimz) -- (0,\dimy,\dimz) -- cycle;%
\draw[cuboid/emphstyle] (0,\dimy,\dimz) -- (0,0,\dimz) -- (\dimx,0,\dimz) -- (\dimx,\dimy,\dimz);%
\draw[cuboid/emphstyle] (\dimx,\dimy,0) -- (\dimx,0,0) -- (\dimx,0,\dimz);%
\fi
\ifcuboidshade
\pgfmathsetmacro{\cstepx}{\dimx/\tikzcuboidkey{shadesamples}}
\pgfmathsetmacro{\cstepy}{\dimy/\tikzcuboidkey{shadesamples}}
\pgfmathsetmacro{\cstepz}{\dimz/\tikzcuboidkey{shadesamples}}
\foreach \s in {1,...,\tikzcuboidkey{shadesamples}}
{ \pgfmathsetmacro{\lows}{\s-1}
\pgfmathsetmacro{\cpercent}{(\lows)/(\tikzcuboidkey{shadesamples}-1)*100}
\fill[opacity=\tikzcuboidkey{shadeopacity},color=\tikzcuboidkey{shadecolorlight}!\cpercent!\tikzcuboidkey{shadecolordark}] (0,\s*\cstepy,\dimz) -- (\s*\cstepx,\s*\cstepy,\dimz) -- (\s*\cstepx,0,\dimz) -- (\lows*\cstepx,0,\dimz) -- (\lows*\cstepx,\lows*\cstepy,\dimz) -- (0,\lows*\cstepy,\dimz) -- cycle;
\fill[opacity=\tikzcuboidkey{shadeopacity},color=\tikzcuboidkey{shadecolorlight}!\cpercent!\tikzcuboidkey{shadecolordark}] (0,\dimy,\s*\cstepz) -- (\s*\cstepx,\dimy,\s*\cstepz) -- (\s*\cstepx,\dimy,0) -- (\lows*\cstepx,\dimy,0) -- (\lows*\cstepx,\dimy,\lows*\cstepz) -- (0,\dimy,\lows*\cstepz) -- cycle;
\fill[opacity=\tikzcuboidkey{shadeopacity},color=\tikzcuboidkey{shadecolorlight}!\cpercent!\tikzcuboidkey{shadecolordark}] (\dimx,0,\s*\cstepz) -- (\dimx,\s*\cstepy,\s*\cstepz) -- (\dimx,\s*\cstepy,0) -- (\dimx,\lows*\cstepy,0) -- (\dimx,\lows*\cstepy,\lows*\cstepz) -- (\dimx,0,\lows*\cstepz) -- cycle;
}
\fi
\end{scope}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\tikzcuboid{%
shiftx=0cm,%
shifty=0cm,%
scale=1.00,%
rotation=0,%
densityx=1,%
densityy=1,%
densityz=1,%
dimx=4,%
dimy=1,%
dimz=4,%
front/.style={draw=blue!75!black,fill=blue!25!white},%
right/.style={draw=blue!25!black,fill=blue!75!white},%
top/.style={draw=blue!50!black,fill=blue!50!white},%
anglex=-7,%
angley=90,%
anglez=221.5,%
scalex=0.8,%
scaley=2.0,%
scalez=0.5,%
emphedge=false,%
shade,%
shadeopacity=0.15,%
xedgelabel={3.2m},%
yedgelabel={2m},%
zedgelabel={3.2m},%
/tikz/edgelabel/.style={sloped},
}
\end{tikzpicture}
\end{document}