答案1
这是一个使用正交投影的版本。也就是说,你可以调整视角,至少在一定程度上,而且视图是真实的(在远距离观察者的极限内)。一切都存储在 pgf 键中,因此高度可调。样式和键基本上取自这个答案和这个答案,您可以找到动画说明了视图可调的含义。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\tikzset{plane/.style n args={3}{insert path={%
#1 -- ++ #2 -- ++ #3 -- ++ ($-1*#2$) -- cycle}},
unit xy plane/.style={plane={#1}{(\CubeX,0,0)}{(0,\CubeY,0)}},
unit xz plane/.style={plane={#1}{(\CubeX,0,0)}{(0,0,\CubeZ)}},
unit yz plane/.style={plane={#1}{(0,\CubeY,0)}{(0,0,\CubeZ)}},
get projections/.style={insert path={%
let \p1=(1,0,0),\p2=(0,1,0) in
[/utils/exec={\pgfmathtruncatemacro{\xproj}{sign(\x1)}\xdef\xproj{\xproj}
\pgfmathtruncatemacro{\yproj}{sign(\x2)}\xdef\yproj{\yproj}
\pgfmathtruncatemacro{\zproj}{sign(cos(\tdplotmaintheta))}\xdef\zproj{\zproj}}]}},
pics/unit cube/.style={code={
\path[get projections];
\ifnum\zproj=-1
\path[3d cube/every face,3d cube/xy face,unit xy plane={(-\CubeX/2,-\CubeY/2,-\CubeZ/2)}];
\fi
\ifnum\yproj=1
\path[3d cube/every face,3d cube/yz face,unit yz plane={(\CubeX/2,-\CubeY/2,-\CubeZ/2)}];
\else
\path[3d cube/every face,3d cube/yz face,unit yz plane={(-\CubeX/2,-\CubeY/2,-\CubeZ/2)}];
\fi
\ifnum\xproj=1
\path[3d cube/every face,3d cube/xz face,unit xz plane={(-\CubeX/2,-\CubeY/2,-\CubeZ/2)}];
\else
\path[3d cube/every face,3d cube/xz face,unit xz plane={(-\CubeX/2,\CubeY/2,-\CubeZ/2)}];
\fi
\ifnum\zproj>-1
\path[3d cube/every face,3d cube/xy face,unit xy plane={(-\CubeX/2,-\CubeY/2,\CubeZ/2)}];
\fi
}},
3d cube/.cd,
xy face/.style={fill=red!20},
xz face/.style={fill=blue!20},
yz face/.style={fill=orange!30},
num cubes x/.estore in=\NumCubesX,
num cubes y/.estore in=\NumCubesY,
num cubes z/.estore in=\NumCubesZ,
num cubes x/.initial=1,num cubes y/.initial=1,num cubes z/.initial=1,
cube x/.estore in=\CubeX,
cube y/.estore in=\CubeY,
cube z/.estore in=\CubeZ,
cube x=1,cube y=1,cube z=1,
cube scale/.initial=1,
every face/.style={draw,very thick},
/tikz/pics/.cd,
cube array/.style={code={%
\tikzset{3d cube/.cd,#1}
%\typeout{\NumCubesX,\NumCubesY,\NumCubesZ}
\path[get projections];
\ifnum\yproj=1
\def\LstX{1,...,\NumCubesX}
\else
\ifnum\NumCubesX>1
\pgfmathtruncatemacro{\NextToLast}{\NumCubesX-1}
\def\LstX{\NumCubesX,\NextToLast,...,1}
\else
\def\LstX{1}
\fi
\fi
\ifnum\xproj=-1
\def\LstY{1,...,\NumCubesY}
\else
\ifnum\NumCubesY>1
\pgfmathtruncatemacro{\NextToLast}{\NumCubesY-1}
\def\LstY{\NumCubesY,\NextToLast,...,1}
\else
\def\LstY{1}
\fi
\fi
\ifnum\zproj=1
\def\LstZ{1,...,\NumCubesZ}
\else
\ifnum\NumCubesZ>1
\pgfmathtruncatemacro{\NextToLast}{\NumCubesZ-1}
\def\LstZ{\NumCubesZ,\NextToLast,...,1}
\else
\def\LstZ{1}
\fi
\fi
\foreach \X in \LstX
{\foreach \Y in \LstY
{\foreach \Z in \LstZ
{\path (\X-\NumCubesX/2-1/2,\Y-\NumCubesY/2-1/2,\Z-\NumCubesY/2-1/2)
pic[scale=\pgfkeysvalueof{/tikz/3d cube/cube scale}]{unit cube};}}
}
}}
}
\begin{document}
\tdplotsetmaincoords{70}{50} % the first argument cannot be larger than 90
\begin{tikzpicture}[line join=round,tdplot_main_coords,font=\sffamily,3d cube/.cd,
num cubes x=1,num cubes y=1,num cubes z=1]
\begin{scope}
% top left
\path (-3,0,0) pic{cube array={num cubes y=3,num cubes z=3}}
++(1,-1/2,1/2) pic{cube array={num cubes y=2,num cubes z=2}}
++(1,-1/2,1/2) pic{cube array={num cubes y=1,num cubes z=1}};
% top right
\path (3,3,0) pic{cube array={num cubes x=3,num cubes z=3}}
++ (1/2,-1,1) pic{cube array={num cubes x=2,num cubes z=2}}
++ (1/2,-1,1) pic{cube array={num cubes y=1,num cubes z=1}};
% bottom
\path (0,2,-3) pic{cube array={num cubes x=3,num cubes y=3}}
++ (1/2,-1/2,1/2) pic{cube array={num cubes x=2,num cubes y=2}}
++ (1/2,-1/2,1/2) pic{cube array={num cubes x=1,num cubes y=1}};
\end{scope}
\begin{scope}[xshift=11cm]
% top left
\path (0,0,-1) pic{cube array={num cubes x=4,num cubes y=3,num cubes z=3}}
(1/2,1,1) pic{cube array={num cubes x=3,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=2,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=1,num cubes y=1,num cubes z=1}};
\draw[line width=2pt] (-1,-1.5,-5/2) -- ++ (0,0,1)
-- ++ (1,0,0) -- ++ (0,0,1) -- ++ (1,0,0) -- ++ (0,0,1)
-- ++ (1,0,0) -- ++ (0,1,0) -- ++ (0,0,-1) -- ++ (0,1,0) -- ++ (0,0,-1)
-- ++ (0,1,0) -- ++ (0,0,-1);
\end{scope}
\tikzset{darker/.style={3d cube/.cd,cube z=1/2,xy face/.style={fill=red!40},
xz face/.style={fill=blue!40},yz face/.style={fill=orange!60}}}
\begin{scope}[yshift=-8cm]
% top left
\path (0,0,-1) pic{cube array={num cubes x=4,num cubes y=3,num cubes z=3}};
\path[3d cube/cube z=1/2]
(1/2,1,3/4) pic{cube array={num cubes x=3,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=2,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=1,num cubes y=1,num cubes z=1}};
\path[3d cube/.cd,cube z=1/2]
(1/2,1,3/4) pic{cube array={num cubes x=3,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=2,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=1,num cubes y=1,num cubes z=1}};
\path[darker]
(1/2,1,5/4) pic{cube array={num cubes x=3,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=2,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=1,num cubes y=1,num cubes z=1}};
\end{scope}
\begin{scope}[yshift=-8cm,xshift=11cm]
% top left
\path (0,0,-1) pic{cube array={num cubes x=4,num cubes y=3,num cubes z=3}};
\path[3d cube/.cd,cube z=1/2]
(-3/2,1,3/4) pic[darker]{cube array={num cubes x=1,num cubes y=1,num cubes z=1}}
(1/2,1,3/4) pic{cube array={num cubes x=3,num cubes y=1,num cubes z=1}}
(-1,0,3/4) pic[darker]{cube array={num cubes x=2,num cubes y=1,num cubes z=1}}
(1,0,3/4) pic{cube array={num cubes x=2,num cubes y=1,num cubes z=1}}
(-1/2,-1,3/4) pic[darker]{cube array={num cubes x=3,num cubes y=1,num cubes z=1}}
(3/2,-1,3/4) pic{cube array={num cubes x=1,num cubes y=1,num cubes z=1}};
\end{scope}
\end{tikzpicture}
\end{document}
为了允许非平凡的不透明度,还需要绘制隐藏的面,因为如果覆盖它们的面变得透明,它们就会取消隐藏。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\tikzset{plane/.style n args={3}{insert path={%
#1 -- ++ #2 -- ++ #3 -- ++ ($-1*#2$) -- cycle}},
unit xy plane/.style={plane={#1}{(\CubeX,0,0)}{(0,\CubeY,0)}},
unit xz plane/.style={plane={#1}{(\CubeX,0,0)}{(0,0,\CubeZ)}},
unit yz plane/.style={plane={#1}{(0,\CubeY,0)}{(0,0,\CubeZ)}},
get projections/.style={insert path={%
let \p1=(1,0,0),\p2=(0,1,0) in
[/utils/exec={\pgfmathtruncatemacro{\xproj}{sign(\x1)}\xdef\xproj{\xproj}
\pgfmathtruncatemacro{\yproj}{sign(\x2)}\xdef\yproj{\yproj}
\pgfmathtruncatemacro{\zproj}{sign(cos(\tdplotmaintheta))}\xdef\zproj{\zproj}}]}},
pics/unit cube/.style={code={
\path[get projections];
\ifnum\zproj=-1
\path[3d cube/every face,3d cube/xy face,unit xy plane={(-\CubeX/2,-\CubeY/2,-\CubeZ/2)}];
\else
\path[3d cube/every face,3d cube/xy face,unit xy plane={(-\CubeX/2,-\CubeY/2,\CubeZ/2)}];
\fi
\ifnum\yproj=1
\path[3d cube/every face,3d cube/yz face,unit yz plane={(-\CubeX/2,-\CubeY/2,-\CubeZ/2)}];
\else
\path[3d cube/every face,3d cube/yz face,unit yz plane={(\CubeX/2,-\CubeY/2,-\CubeZ/2)}];
\fi
\ifnum\xproj=1
\path[3d cube/every face,3d cube/xz face,unit xz plane={(-\CubeX/2,\CubeY/2,-\CubeZ/2)}];
\else
\path[3d cube/every face,3d cube/xz face,unit xz plane={(-\CubeX/2,-\CubeY/2,-\CubeZ/2)}];
\fi
\ifnum\yproj=1
\path[3d cube/every face,3d cube/yz face,unit yz plane={(\CubeX/2,-\CubeY/2,-\CubeZ/2)}];
\else
\path[3d cube/every face,3d cube/yz face,unit yz plane={(-\CubeX/2,-\CubeY/2,-\CubeZ/2)}];
\fi
\ifnum\xproj=1
\path[3d cube/every face,3d cube/xz face,unit xz plane={(-\CubeX/2,-\CubeY/2,-\CubeZ/2)}];
\else
\path[3d cube/every face,3d cube/xz face,unit xz plane={(-\CubeX/2,\CubeY/2,-\CubeZ/2)}];
\fi
\ifnum\zproj>-1
\path[3d cube/every face,3d cube/xy face,unit xy plane={(-\CubeX/2,-\CubeY/2,\CubeZ/2)}];
\else
\path[3d cube/every face,3d cube/xy face,unit xy plane={(-\CubeX/2,-\CubeY/2,-\CubeZ/2)}];
\fi
}},
3d cube/.cd,
xy face/.style={fill=red!20},
xz face/.style={fill=blue!20},
yz face/.style={fill=orange!30},
num cubes x/.estore in=\NumCubesX,
num cubes y/.estore in=\NumCubesY,
num cubes z/.estore in=\NumCubesZ,
num cubes x/.initial=1,num cubes y/.initial=1,num cubes z/.initial=1,
cube x/.estore in=\CubeX,
cube y/.estore in=\CubeY,
cube z/.estore in=\CubeZ,
cube x=1,cube y=1,cube z=1,
cube scale/.initial=1,
every face/.style={draw,very thick},
/tikz/pics/.cd,
cube array/.style={code={%
\tikzset{3d cube/.cd,#1}
%\typeout{\NumCubesX,\NumCubesY,\NumCubesZ}
\path[get projections];
\ifnum\yproj=1
\def\LstX{1,...,\NumCubesX}
\else
\ifnum\NumCubesX>1
\pgfmathtruncatemacro{\NextToLast}{\NumCubesX-1}
\def\LstX{\NumCubesX,\NextToLast,...,1}
\else
\def\LstX{1}
\fi
\fi
\ifnum\xproj=-1
\def\LstY{1,...,\NumCubesY}
\else
\ifnum\NumCubesY>1
\pgfmathtruncatemacro{\NextToLast}{\NumCubesY-1}
\def\LstY{\NumCubesY,\NextToLast,...,1}
\else
\def\LstY{1}
\fi
\fi
\ifnum\zproj=1
\def\LstZ{1,...,\NumCubesZ}
\else
\ifnum\NumCubesZ>1
\pgfmathtruncatemacro{\NextToLast}{\NumCubesZ-1}
\def\LstZ{\NumCubesZ,\NextToLast,...,1}
\else
\def\LstZ{1}
\fi
\fi
\foreach \X in \LstX
{\foreach \Y in \LstY
{\foreach \Z in \LstZ
{\path (\X-\NumCubesX/2-1/2,\Y-\NumCubesY/2-1/2,\Z-\NumCubesY/2-1/2)
pic[scale=\pgfkeysvalueof{/tikz/3d cube/cube scale}]{unit cube};}}
}
}}
}
\begin{document}
\tdplotsetmaincoords{70}{50} % the first argument cannot be larger than 90
\begin{tikzpicture}[line join=round,tdplot_main_coords,font=\sffamily,3d cube/.cd,
num cubes x=1,num cubes y=1,num cubes z=1]
\begin{scope}
% top left
\path (-3,0,0) pic{cube array={num cubes y=3,num cubes z=3}}
++(1,-1/2,1/2) pic{cube array={num cubes y=2,num cubes z=2}}
++(1,-1/2,1/2) pic{cube array={num cubes y=1,num cubes z=1}};
% top right
\path (3,3,0) pic{cube array={num cubes x=3,num cubes z=3}}
++ (1/2,-1,1) pic{cube array={num cubes x=2,num cubes z=2}}
++ (1/2,-1,1) pic{cube array={num cubes y=1,num cubes z=1}};
% bottom
\path (0,2,-3) pic{cube array={num cubes x=3,num cubes y=3}}
++ (1/2,-1/2,1/2) pic{cube array={num cubes x=2,num cubes y=2}}
++ (1/2,-1/2,1/2) pic{cube array={num cubes x=1,num cubes y=1}};
\end{scope}
\begin{scope}[xshift=11cm]
% top left
\path (0,0,-1) pic{cube array={num cubes x=4,num cubes y=3,num cubes z=3}}
(1/2,1,1) pic{cube array={num cubes x=3,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=2,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=1,num cubes y=1,num cubes z=1}};
\draw[line width=2pt] (-1,-1.5,-5/2) -- ++ (0,0,1)
-- ++ (1,0,0) -- ++ (0,0,1) -- ++ (1,0,0) -- ++ (0,0,1)
-- ++ (1,0,0) -- ++ (0,1,0) -- ++ (0,0,-1) -- ++ (0,1,0) -- ++ (0,0,-1)
-- ++ (0,1,0) -- ++ (0,0,-1);
\end{scope}
\tikzset{darker/.style={3d cube/.cd,cube z=1/2,xy face/.style={fill=red!40},
xz face/.style={fill=blue!40},yz face/.style={fill=orange!60}}}
\begin{scope}[yshift=-8cm]
% top left
\path (0,0,-1) pic{cube array={num cubes x=4,num cubes y=3,num cubes z=3}};
\path[3d cube/cube z=1/2]
(1/2,1,3/4) pic{cube array={num cubes x=3,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=2,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=1,num cubes y=1,num cubes z=1}};
\path[3d cube/.cd,cube z=1/2]
(1/2,1,3/4) pic{cube array={num cubes x=3,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=2,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=1,num cubes y=1,num cubes z=1}};
\path[darker,/tikz/opacity=0.6]
(1/2,1,5/4) pic{cube array={num cubes x=3,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=2,num cubes y=1,num cubes z=1}}
++(1/2,-1,0) pic{cube array={num cubes x=1,num cubes y=1,num cubes z=1}};
\end{scope}
\begin{scope}[yshift=-8cm,xshift=11cm]
% top left
\path (0,0,-1) pic{cube array={num cubes x=4,num cubes y=3,num cubes z=3}};
\path[3d cube/.cd,cube z=1/2,/tikz/opacity=0.6]
(-3/2,1,3/4) pic[darker]{cube array={num cubes x=1,num cubes y=1,num cubes z=1}}
(1/2,1,3/4) pic{cube array={num cubes x=3,num cubes y=1,num cubes z=1}}
(-1,0,3/4) pic[darker]{cube array={num cubes x=2,num cubes y=1,num cubes z=1}}
(1,0,3/4) pic{cube array={num cubes x=2,num cubes y=1,num cubes z=1}}
(-1/2,-1,3/4) pic[darker]{cube array={num cubes x=3,num cubes y=1,num cubes z=1}}
(3/2,-1,3/4) pic{cube array={num cubes x=1,num cubes y=1,num cubes z=1}};
\end{scope}
\end{tikzpicture}
\end{document}
答案2
这里给出一个答案:我们可以很好地使用 Jang Soo Kim 的代码例程来复制这个无需言语的证明。
这是结果,复制并不准确,因为这个透视的角度破坏了透视效果。
因此,在不改变常规的情况下,我修改了一些面的角度和长度,以获得更好的 3D 渲染。
结果如下:
以下是本回答中我自己修改的Jang Soo Kim代码生成的图的代码:https://tex.stackexchange.com/a/470985/138900 (图片位于本页顶部)
\documentclass[tikz,border=5mm]{standalone}
% Three counters
\newcounter{x}
\newcounter{y}
\newcounter{z}
% The angles of x,y,z-axes
\newcommand\xaxis{210}
\newcommand\yaxis{-30}
\newcommand\zaxis{90}
% The top side of a cube
\newcommand\topside[3]{
\fill[fill=yellow!30,fill opacity=1, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
shift={(\zaxis:#3)}] (0,0) -- (30:1) -- (0,1) --(150:1)--(0,0);
}
% The left side of a cube
\newcommand\leftside[3]{
\fill[fill=cyan!50,fill opacity=1, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
shift={(\zaxis:#3)}] (0,0) -- (0,-1) -- (210:1) --(150:1)--(0,0);
}
% The right side of a cube
\newcommand\rightside[3]{
\fill[fill=yellow!40!green!80!white,fill opacity=1, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
shift={(\zaxis:#3)}] (0,0) -- (30:1) -- (-30:1) --(0,-1)--(0,0);
}
% The cube
\newcommand\cube[3]{
\topside{#1}{#2}{#3} \leftside{#1}{#2}{#3} \rightside{#1}{#2}{#3}
}
% Definition of \planepartition
% To draw the following plane partition, just write \planepartition{ {a, b, c}, {d,e} }.
% a b c
% d e
\newcommand\planepartition[2][0]{
\setcounter{x}{-1}
\foreach \a in {#2} {
\addtocounter{x}{1}
\setcounter{y}{-1}
\foreach \b in \a {
\addtocounter{y}{1}
\setcounter{z}{-1}
\addtocounter{z}{#1} %partition of the desired floor (layer)
\ifnum \b>0
\foreach \c in {1,...,\b} {
\addtocounter{z}{1}
\cube{\value{x}}{\value{y}}{\value{z}}
}\fi
}
}
}
\begin{document}
\begin{tikzpicture}
\planepartition{{3},{3},{3}}% Old syntax is functional
\planepartition[1]{{0,0},{0,2},{0,2}}
\planepartition[2]{{0},{0},{0,0,1}}
\begin{scope}[xshift=5cm]
\planepartition{{3,3,3}}% Old syntax is functional
\planepartition[1]{{0},{0,2,2}}
\planepartition[2]{{0},{0},{0,0,1}}
\end{scope}
\begin{scope}[shift={(3,-4)}]
\planepartition{{1},{1},{1}}
\planepartition{{0,1},{0,2},{0,2}}
\planepartition{{0,0,1},{0,0,2},{0,0,3}}
\end{scope}
\end{tikzpicture}
\end{document}
该算法(marmot称之为例程),即命令的代码\planepartition
尚未被修改。
\newcommand\planepartition[2][0]{
\setcounter{x}{-1}
\foreach \a in {#2} {
\addtocounter{x}{1}
\setcounter{y}{-1}
\foreach \b in \a {
\addtocounter{y}{1}
\setcounter{z}{-1}
\addtocounter{z}{#1} %partition of the desired floor (layer)
\ifnum \b>0
\foreach \c in {1,...,\b} {
\addtocounter{z}{1}
\cube{\value{x}}{\value{y}}{\value{z}}
}\fi
}
}
}
仅修改了初始条件(角度和面长)。\planepartition
两个版本中对例程 ( ) 的调用相同:
\begin{tikzpicture}
\planepartition{{3},{3},{3}}% Old syntax is functional
\planepartition[1]{{0,0},{0,2},{0,2}}
\planepartition[2]{{0},{0},{0,0,1}}
\begin{scope}[xshift=5cm]
\planepartition{{3,3,3}}% Old syntax is functional
\planepartition[1]{{0},{0,2,2}}
\planepartition[2]{{0},{0},{0,0,1}}
\end{scope}
\begin{scope}[shift={(3,-4)}]
\planepartition{{1},{1},{1}}
\planepartition{{0,1},{0,2},{0,2}}
\planepartition{{0,0,1},{0,0,2},{0,0,3}}
\end{scope}
\end{tikzpicture}
完整代码:
\documentclass[tikz,border=5mm]{standalone}
\newcounter{x}
\newlength{\x}
\setlength{\x}{.8cm}
\newcounter{y}
\newcounter{z}
% The angles of x,y,z-axes
\def\xangle{30}
\def\yangle{10}
\newcommand\xaxis{180+\xangle}
\newcommand\yaxis{-\yangle}
\newcommand\zaxis{90}
% The top side of a cube
\newcommand\topside[3]{
\fill[fill=yellow!60,fill opacity=1, draw=black,shift={(\xaxis:#1\x)},shift={(\yaxis:#2)},
shift={(\zaxis:#3)}] (0,0) -- (\xangle:\x) --++ (180-\yangle:1) --++(180+\xangle:\x)--cycle;
}
% The left side of a cube
\newcommand\leftside[3]{
\fill[fill=orange!60,fill opacity=1, draw=black,shift={(\xaxis:#1\x)},shift={(\yaxis:#2)},
shift={(\zaxis:#3)}] (0,0) -- (0,-1) --++ (180-\yangle:1) --(180-\yangle:1)--(0,0);
}
% The right side of a cube
\newcommand\rightside[3]{
\fill[fill=blue!60,fill opacity=1, draw=black,shift={(\xaxis:#1\x)},shift={(\yaxis:#2)},
shift={(\zaxis:#3)}] (0,0) -- (\xangle:\x) --++ (0,-1)--(0,-1)--(0,0);
}
% The cube
\newcommand\cube[3]{
\topside{#1}{#2}{#3} \leftside{#1}{#2}{#3} \rightside{#1}{#2}{#3}
}
% Definition of \planepartition
% To draw the following plane partition, just write \planepartition{ {a, b, c}, {d,e} }.
% a b c
% d e
\newcommand\planepartition[2][0]{
\setcounter{x}{-1}
\foreach \a in {#2} {
\addtocounter{x}{1}
\setcounter{y}{-1}
\foreach \b in \a {
\addtocounter{y}{1}
\setcounter{z}{-1}
\addtocounter{z}{#1} %partition of the desired floor (layer)
\ifnum \b>0
\foreach \c in {1,...,\b} {
\addtocounter{z}{1}
\cube{\value{x}}{\value{y}}{\value{z}}
}\fi
}
}
}
\begin{document}
\begin{tikzpicture}
\planepartition{{3},{3},{3}}% Old syntax is functional
\planepartition[1]{{0,0},{0,2},{0,2}}
\planepartition[2]{{0},{0},{0,0,1}}
\begin{scope}[xshift=5cm]
\planepartition{{3,3,3}}% Old syntax is functional
\planepartition[1]{{0},{0,2,2}}
\planepartition[2]{{0},{0},{0,0,1}}
\end{scope}
\begin{scope}[shift={(3,-4)}]
\planepartition{{1},{1},{1}}
\planepartition{{0,1},{0,2},{0,2}}
\planepartition{{0,0,1},{0,0,2},{0,0,3}}
\end{scope}
\end{tikzpicture}
\end{document}
使用 www.DeepL.com/Translator 翻译