帮助使用 tikz 图片创建块

帮助使用 tikz 图片创建块

我正在尝试说明通常的位值立方体,到目前为止我已经:

    \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{{1},{0},{0}}% Old syntax is functional

    \begin{scope}[xshift=5cm]
    \planepartition{{10,0,0}}% Old syntax is functional

    \end{scope}

    \begin{scope}[shift={(3,-4)}]
    \planepartition{{10},{10},{10}}
    \end{scope}
    \end{tikzpicture}
    \end{document} 

但我不明白为什么最后一个没有产生 10 x 10 的图表,有人可以帮忙吗?

答案1

我不明白哪里不起作用。如果我从更改\begin{document}\end{document}这种方式:

\begin{document} 
    
    \begin{tikzpicture}
        \planepartition{{2},{1},{0}}% Old syntax is functional
        
        \begin{scope}[xshift=8cm]
            \planepartition{{10,8,6,7},{3,7,2},{2,5}}% Old syntax is functional
            
        \end{scope}
        
        \begin{scope}[shift={(3,-4)}]
            \planepartition{{3,3,3},{3,3,3},{3,3,3}}
        \end{scope}
    \end{tikzpicture}
\end{document}

我所要求的正是:

在此处输入图片描述

相关内容