如何通过堆叠单位立方体得出十位数

如何通过堆叠单位立方体得出十位数

我正在尝试用 tikz 中的单位立方体制作数字。这是数字六,并且有一个错误,正如您将看到的。如何纠正此问题在此处输入图片描述

\documentclass[oneside]{standalone}
\usepackage{amssymb, latexsym, amscd, amsthm, amsmath}

\usepackage{tikz}
\usetikzlibrary{calc,decorations,decorations.pathmorphing}

\newcommand{\tikzcuboid}[4]{% width, height, depth, scale
\begin{tikzpicture}[scale=#4]
\foreach \x in {0,...,#1}
{   \draw (\x ,0  ,#3 ) -- (\x ,#2 ,#3 );
    \draw (\x ,#2 ,#3 ) -- (\x ,#2 ,0  );
}
\foreach \x in {0,...,#2}
{   \draw (#1 ,\x ,#3 ) -- (#1 ,\x ,0  );
    \draw (0  ,\x ,#3 ) -- (#1 ,\x ,#3 );
}
\foreach \x in {0,...,#3}
{   \draw (#1 ,0  ,\x ) -- (#1 ,#2 ,\x );
    \draw (0  ,#2 ,\x ) -- (#1 ,#2 ,\x );
}
\end{tikzpicture}
}

\newcommand{\drawbox}[4]{
    \pgfmathsetmacro \angle {30}
    \pgfmathsetmacro \xd {{2/3*cos(\angle)}}
    \pgfmathsetmacro \yd {{2/3*sin(\angle)}}
    \pgfmathsetmacro \x {{#1-1+(#2-1)*(\xd)}}
    \pgfmathsetmacro \y {{#3-1+(#2-1)*(\yd)}}

    \draw[fill=#4] (\x,\y) -- (\x+1,\y) -- (\x+1,\y+1) -- (\x,\y+1) -- cycle;
    \draw[fill=#4] (\x,\y+1) -- (\x+\xd,\y+1+\yd) -- (\x+1+\xd,\y+1+\yd) -- (\x+1,\y+1) -- cycle;
    \draw[fill=#4] (\x+1,\y+1) -- (\x+1+\xd,\y+1+\yd) -- (\x+1+\xd,\y+\yd) -- (\x+1,\y) -- cycle;
}



   \begin{document}


\begin{tikzpicture}[rotate=.8512, scale=.352830487, line width=.673pt]
        \drawbox{2}{3}{-1}{blue!21} 
 \drawbox{2}{3}{-3}{blue!21} 
 \drawbox{2}{3}{-2}{blue!21} 
 \drawbox{2}{3}{-1}{blue!21} 

\drawbox{2}{3}{0}{blue!21} 
    \drawbox{2}{3}{1}{blue!21}

    \drawbox{3}{3}{1}{blue!21}
        \drawbox{4}{3}{1}{blue!21}
      \drawbox{5}{3}{1}{blue!21}
                \drawbox{6}{3}{1}{blue!21}        
\drawbox{3}{3}{-3}{blue!21}
\drawbox{4}{3}{-3}{blue!21}
\drawbox{5}{3}{-3}{blue!21}

\drawbox{2}{3}{-7}{blue!21} 
\drawbox{2}{3}{-6}{blue!21} 


\drawbox{3}{3}{-7}{blue!21} 
\drawbox{4}{3}{-7}{blue!21} 
\drawbox{5}{3}{-7}{blue!21} 
\drawbox{6}{3}{-7}{blue!21}
\drawbox{6}{3}{-6}{blue!21} 
 \drawbox{6}{3}{-5}{blue!21} 

\drawbox{6}{3}{-4}{blue!21} 
\drawbox{6}{3}{-3}{blue!21} 


\drawbox{2}{2}{-5}{blue!21} 

\drawbox{2}{3}{-4}{blue!21} 
\drawbox{2}{3}{-5}{blue!21} 

\drawbox{2}{2}{-4}{blue!21} 


\drawbox{2}{2}{-5}{blue!21} 

\drawbox{2}{3}{-4}{blue!21} 
\drawbox{2}{2}{-4}{blue!21} 


          \drawbox{2}{2}{-1}{blue!21} 
 \drawbox{2}{2}{-3}{blue!21} 
 \drawbox{2}{2}{-2}{blue!21} 
 \drawbox{2}{2}{-1}{blue!21} 

\drawbox{2}{2}{0}{blue!21} 
    \drawbox{2}{2}{1}{blue!21}

    \drawbox{3}{2}{1}{blue!21}
        \drawbox{4}{2}{1}{blue!21}
        \drawbox{5}{2}{1}{blue!21}
                \drawbox{6}{2}{1}{blue!21}        
\drawbox{3}{2}{-3}{blue!21}
\drawbox{4}{2}{-3}{blue!21}
\drawbox{5}{2}{-3}{blue!21}
\drawbox{6}{2}{-3}{blue!21} 


\drawbox{2}{2}{-7}{blue!21} 
\drawbox{2}{2}{-6}{blue!21} 



\drawbox{3}{2}{-7}{blue!21} 
\drawbox{4}{2}{-7}{blue!21} 
\drawbox{5}{2}{-7}{blue!21} 
\drawbox{6}{2}{-7}{blue!21}
\drawbox{6}{2}{-6}{blue!21} 
 \drawbox{6}{2}{-5}{blue!21} 

\drawbox{6}{2}{-4}{blue!21} 
\drawbox{6}{2}{-3}{blue!21} 


\end{tikzpicture}

\end{document}

答案1

你的顺序稍微有点错误:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\newcommand{\drawbox}[4]{
  \pgfmathsetmacro \angle {30}
  \pgfmathsetmacro \xd {{2/3*cos(\angle)}}
  \pgfmathsetmacro \yd {{2/3*sin(\angle)}}
  \pgfmathsetmacro \x {{#1-1+(#2-1)*(\xd)}}
  \pgfmathsetmacro \y {{#3-1+(#2-1)*(\yd)}}
  \draw[fill=#4] (\x,\y) -- (\x+1,\y) -- (\x+1,\y+1) -- (\x,\y+1) -- cycle;
  \draw[fill=#4] (\x,\y+1) -- (\x+\xd,\y+1+\yd) -- (\x+1+\xd,\y+1+\yd) -- (\x+1,\y+1) -- cycle;
  \draw[fill=#4] (\x+1,\y+1) -- (\x+1+\xd,\y+1+\yd) -- (\x+1+\xd,\y+\yd) -- (\x+1,\y) -- cycle;
}
\begin{document}
  \begin{tikzpicture}[rotate=.8512, scale=.352830487, line width=.673pt,join=round]
    \drawbox{2}{3}{-1}{blue!21} 
  \drawbox{2}{3}{-3}{blue!21} 
  \drawbox{2}{3}{-2}{blue!21} 
  \drawbox{2}{3}{-1}{blue!21} 

  \drawbox{2}{3}{0}{blue!21} 
  \drawbox{2}{3}{1}{blue!21}

  \drawbox{3}{3}{1}{blue!21}
  \drawbox{4}{3}{1}{blue!21}
  \drawbox{5}{3}{1}{blue!21}
  \drawbox{6}{3}{1}{blue!21}        
  \drawbox{3}{3}{-3}{blue!21}
  \drawbox{4}{3}{-3}{blue!21}
  \drawbox{5}{3}{-3}{blue!21}

  \drawbox{2}{3}{-7}{blue!21} 
  \drawbox{2}{3}{-6}{blue!21} 

  \drawbox{3}{3}{-7}{blue!21} 
  \drawbox{4}{3}{-7}{blue!21} 
  \drawbox{5}{3}{-7}{blue!21} 
  \drawbox{6}{3}{-7}{blue!21}
  \drawbox{6}{3}{-6}{blue!21} 
  \drawbox{6}{3}{-5}{blue!21} 

  \drawbox{6}{3}{-4}{blue!21} 
  \drawbox{6}{3}{-3}{blue!21} 

  \drawbox{2}{2}{-7}{blue!21} 
  \drawbox{2}{2}{-6}{blue!21} 

  \drawbox{2}{2}{-5}{blue!21} 

  \drawbox{2}{3}{-4}{blue!21} 
  \drawbox{2}{3}{-5}{blue!21} 

  \drawbox{2}{2}{-4}{blue!21} 

  \drawbox{2}{2}{-5}{blue!21} 

  \drawbox{2}{3}{-4}{blue!21} 
  \drawbox{2}{2}{-4}{blue!21} 

  \drawbox{2}{2}{-1}{blue!21} 
  \drawbox{2}{2}{-3}{blue!21} 
  \drawbox{2}{2}{-2}{blue!21} 
  \drawbox{2}{2}{-1}{blue!21} 

  \drawbox{2}{2}{0}{blue!21} 
  \drawbox{2}{2}{1}{blue!21}

  \drawbox{3}{2}{1}{blue!21}
  \drawbox{4}{2}{1}{blue!21}
  \drawbox{5}{2}{1}{blue!21}
  \drawbox{6}{2}{1}{blue!21}        
  \drawbox{3}{2}{-3}{blue!21}
  \drawbox{4}{2}{-3}{blue!21}
  \drawbox{5}{2}{-3}{blue!21}
  \drawbox{6}{2}{-3}{blue!21} 

  \drawbox{3}{2}{-7}{blue!21} 
  \drawbox{4}{2}{-7}{blue!21} 
  \drawbox{5}{2}{-7}{blue!21} 
  \drawbox{6}{2}{-7}{blue!21}
  \drawbox{6}{2}{-6}{blue!21} 
  \drawbox{6}{2}{-5}{blue!21} 

  \drawbox{6}{2}{-4}{blue!21} 
  \drawbox{6}{2}{-3}{blue!21} 
\end{tikzpicture}
\end{document}

join=round正如 Peter Grill 所建议的那样,改善了结果。

6^3,也许吧?

相关内容