13

How simple/hard would it be to add text to the front face (the red colored face in this example) of the cubes found at http://www.texample.net/tikz/examples/plane-partition/? I have seen examples like this (where text is placed on face of 3d cube) using \node, but I'm not sure where to begin with this particular code.

Here is the code:

% Plane partition
% Author: Jang Soo Kim
\documentclass{minimal}
\usepackage{tikz}
% 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, 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=red, 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=blue, 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[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}
        \cube{\value{x}}{\value{y}}{\value{z}}
      }
    }
  }
}

\begin{document} 

\begin{tikzpicture}
\planepartition{{5,3,2,2},{4,2,2,1},{2,1},{1}}
\end{tikzpicture}

\end{document} 

EDIT: I didn't think to search for the name of the code's author before, but it turned up this related post: TikZ: Plane partitions with labeled faces

It appears that it is still partly unresolved as the text needs to be slanted.

EDIT 2: @AboAmmar Thank you! this is a great start, however even when i slant it properly, it does not seem like it flows with the face. In other words, it doesn't look flush with the face, but more forward facing.

For example:

\node [rotate=-29.9]at (\x+0.5, \y, \n-1.4) {\n}; \fi

Would produce:

code rendering

EDIT 3:

So it seems you can add xslant and yslant to adjust this. It's just a matter of how to fine-tune it to look right.

EDIT 4:

\node [xslant=-.01, yslant=-0.8]at (\x+0.5, \y, \n-1.4) {\n}; \fi

Which produces:

code rendering

  • Change line #16 in the related post you added in the edit to: \node [rotate=45]at (\x+0.5, \y, \n-1.5) {\n}; You will get the slanted text on the required front faces. – AboAmmar Jul 6 '15 at 20:13
  • Please don't use minimal for examples. article or standalone are better choices. (minimal is not designed for this use and can give weird errors for unobvious reasons.) – cfr Jul 7 '15 at 2:38
  • If I am not mistaken, the arctan of the slant value is associated with the angle that the text axis changes. That should be helpful in correlating slants to the angles of the drawing. – Steven B. Segletes Jul 7 '15 at 10:04
10

I have zero proficiency at tikz, and so I apologize for things like shifting, etc. done in a foolhardy manner. But the point I made in a comment and bring to life here is that the slant value corresponds to the tangent of the slant angle. Since your diagram is (do I recall the terminology?) isometric, with axes at 30, 150 and 270 degrees, the required slants can be gotten directly from those angles.

Here, I write a front end to Bruno's Shear transform a "box", in the form of \rotslant{rotation angle}{slant angle}{text}, so that the slant may be input as an angle, rather than in the form of a tangent.

I place the appropriately rot-slanted text on the three faces, showing the x-level, y-level, and z-level, respectively. On the z surfaces, I show both orientations.

Below the tikzfigure, I show \rotslant output in the raw.

% Plane partition
% Author: Jang Soo Kim
\documentclass{article}

\usepackage{graphicx,amssymb,fp}
\newsavebox\foobox
\newcommand\slbox[2]{%
  \FPdiv{\result}{#1}{57.296}% CONVERT deg TO rad
  \FPtan{\result}{\result}%
  \slantbox[\result]{#2}%
}%
\newcommand{\slantbox}[2][30]{%
        \mbox{%
        \sbox{\foobox}{#2}%
        \hskip\wd\foobox
        \pdfsave
        \pdfsetmatrix{1 0 #1 1}%
        \llap{\usebox{\foobox}}%
        \pdfrestore
}}
\newcommand\rotslant[3]{\rotatebox{#1}{\slbox{#2}{#3}}}

\usepackage{tikz}
% 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, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) -- (30:1) -- (0,1) --(150:1)--(0,0);
  \node[shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] at (-.1,.6,.5) {\rotslant{-30}{30}{\the\numexpr1+\value{z}}};
  \node[shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] at (.5,.6,.5) {\rotslant{30}{-30}{\the\numexpr1+\value{z}}};
}

% The left side of a cube
\newcommand\leftside[3]{
  \fill[fill=red, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) -- (0,-1) -- (210:1) --(150:1)--(0,0);
  \node[shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] at (-.6,-.5,-.5) {\rotslant{-30}{-30}{\the\numexpr1+\value{x}}};
}

% The right side of a cube
\newcommand\rightside[3]{
  \fill[fill=blue, draw=black,shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] (0,0) -- (30:1) -- (-30:1) --(0,-1)--(0,0);
  \node[shift={(\xaxis:#1)},shift={(\yaxis:#2)},
  shift={(\zaxis:#3)}] at (.2,-.5,-.5) {\rotslant{30}{30}{\the\numexpr1+\value{y}}};
}

% 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[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}
        \cube{\value{x}}{\value{y}}{\value{z}}
      }
    }
  }
}
\begin{document} 
\begin{tikzpicture}
\planepartition{{5,3,2,2},{4,2,2,1},{2,1},{1}}
\end{tikzpicture}

$+30^\circ$ rotate;$+30^\circ$ slant:
\rotslant{30}{30}{$\square$A}

$-30^\circ$ rotate;$-30^\circ$ slant:
\rotslant{-30}{-30}{$\square$A}

$-30^\circ$ rotate;$+30^\circ$ slant:
\rotslant{-30}{30}{$\square$A}

$+30^\circ$ rotate;$-30^\circ$ slant:
\rotslant{30}{-30}{$\square$A}
\end{document} 

enter image description here

The principal axes of the rot-slanted text will lie along these two directions: rotation angle and 90 + rotation angle - slant angle. For the four instances shown above after the tikzfigure, these angles are

+30 and 90 degrees

-30 and 90 degrees

-30 and 30 degrees

+30 and 150 degrees

which correspond to the isometric angles of the figure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.