다리에서 떨어진 3D 파티션 색칠하기

다리에서 떨어진 3D 파티션 색칠하기

평면 파티션을 레이어별로 색상을 지정하는 방법이 있습니다. 예를 들어, 나는 그에게서 많은 것을 배웠습니다.이 게시물. 저는 두 가지 색상으로 칸막이를 색칠하고 싶습니다. 한 색상은 모서리의 특정 다리에 적용되고 다른 색상은 다른 모든 상자에 적용됩니다.

아래는 내가 사용하는 코드입니다. 이 예에는 "긴" 노란색 다리(x축)가 있고 다른 모든 부분은 녹색이기를 바랍니다. 노란색 다리 위에 있는 모든 것을 녹색으로 만들 수 있지만 여전히 다리 옆에 있는 것, 즉 "바닥에 있는" 것은 얻을 수 없습니다. 이것은 사소한 문제라고 확신하지만 실제로 코드를 수정하는 방법을 모르겠습니다.

\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}

답변1

나는 당신의 코드의 논리를 이해하려고 노력조차 하지 않았다는 것을 인정함으로써 시작하겠습니다. 하지만 스위치를 도입하는 것만으로도

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

y과 가 0인지 만 테스트합니다 z(음수는 사용하지 않음).

여기에 이미지 설명을 입력하세요

음수 좌표도 있는 경우 다음을 사용하세요.

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

대신에.

전체 코드:

\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}

관련 정보