Eine 3D-Partition von einem Bein weg einfärben

Eine 3D-Partition von einem Bein weg einfärben

Es gibt Möglichkeiten, eine ebene Unterteilung Schicht für Schicht zu färben. Ich habe zum Beispiel viel gelernt vondieser Beitrag. Ich möchte eine Trennwand in zwei Farben einfärben, eine Farbe für ein bestimmtes Bein in einer Ecke und eine andere Farbe für alle anderen Kästen.

Unten ist der Code, den ich verwende. Im Beispiel gibt es ein „langes“ gelbes Bein (die x-Achse) und ich möchte, dass alles andere beispielsweise grün ist. Ich kann alles über dem gelben Bein grün machen, aber nicht das, was noch neben dem Bein ist, nämlich „auf dem Boden“. Ich bin sicher, dass dies ein triviales Problem ist, aber ich weiß wirklich nicht, wie ich den Code ändern soll.

\documentclass{article}

\usepackage{xifthen}
\usepackage{verbatim}

\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=cubecolor, 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=cubecolor, 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=cubecolor, 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}
}

\newcommand*\cubecolors[1]{%
\ifcase#1\relax
  \or\colorlet{cubecolor}{yellow}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \else
    \colorlet{cubecolor}{blue}%
  \fi
}

% Definition of \planepartition
% To draw the following plane partition, just write \planepartition{ {a, b, c}, {d,e} }.
%  a b c
%  d e
\newcommand\planepartition[1]{
 \setcounter{x}{-1}
  \foreach \a in {#1} {
    \addtocounter{x}{1}
    \setcounter{y}{-1}
    \foreach \b in \a {
      \addtocounter{y}{1}
      \setcounter{z}{-1}
      \foreach \c in {1,...,\b} {
        \addtocounter{z}{1}
        \cubecolors{\c}
        \cube{\value{x}}{\value{y}}{\value{z}}
      }
    }
  }
}

\usepackage{tikz}


\begin{document}

\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=0.26]
\planepartition{{5,4,2,1},{3,2,1},{1,1},{1,1},{1},{1},{1},{1},{1},{1}}
\end{tikzpicture}
\end{figure}

\end{document}

Antwort1

Lassen Sie mich zunächst zugeben, dass ich nicht einmal versucht habe, die Logik Ihres Codes zu verstehen. Durch die bloße Einführung eines Schalters

 \pgfmathtruncatemacro{\myc}{ifthenelse(\value{y}+\value{z}==0,1,2)}
 \cubecolors{\myc}

das nur prüft, ob yund zNull sind (Sie verwenden keine negativen Zahlen), erhalte ich

Bildbeschreibung hier eingeben

Wenn Sie auch negative Koordinaten haben, verwenden Sie

\pgfmathtruncatemacro{\myc}{ifthenelse(abs(\value{y})+abs(\value{z})==0,1,2)}

stattdessen.

Vollständiger Code:

\documentclass{article}

\usepackage{xifthen}
\usepackage{verbatim}

\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=cubecolor, 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=cubecolor, 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=cubecolor, 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}
}

\newcommand*\cubecolors[1]{%
\ifcase#1\relax
  \or\colorlet{cubecolor}{yellow}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \or\colorlet{cubecolor}{green}%
  \else
    \colorlet{cubecolor}{blue}%
  \fi
}

% Definition of \planepartition
% To draw the following plane partition, just write \planepartition{ {a, b, c}, {d,e} }.
%  a b c
%  d e
\newcommand\planepartition[1]{
 \setcounter{x}{-1}
  \foreach \a in {#1} {
    \addtocounter{x}{1}
    \setcounter{y}{-1}
    \foreach \b in \a {
      \addtocounter{y}{1}
      \setcounter{z}{-1}
      \foreach \c in {1,...,\b} {
        \addtocounter{z}{1}
        \pgfmathtruncatemacro{\myc}{ifthenelse(\value{y}+\value{z}==0,1,2)}
        \cubecolors{\myc}
        \cube{\value{x}}{\value{y}}{\value{z}}
      }
    }
  }
}

\usepackage{tikz}


\begin{document}

\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=0.26]
\planepartition{{5,4,2,1},{3,2,1},{1,1},{1,1},{1},{1},{1},{1},{1},{1}}
\end{tikzpicture}
\end{figure}

\end{document}

verwandte Informationen