# Truncated cube with numerated faces

I am having difficulties to project texts in inclined planes. To be more precise, i would like do latex the following question.

Exercise: In the following figure, we see two different views of a truncated cube, with 14 numerated faces. What is the number in the opposite face of the face with 13 number? I did the left figure in TikZ and I put the numbers on the figure using xslant, yslant and rotation. However the final result was not satisfactory and it was very laborious and somewhat arbitrarily to determine the parameters of xslan, yslant and rotation commands. The code I typed and the figure obtained are these.

\documentclass[]{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}

\begin{document}

\tdplotsetmaincoords{75}{105}
\centerline{
\begin{tikzpicture} [tdplot_main_coords]
\def\a{1.1}; %-- half of the edge of the cube
%-----faces with 4 edges ----------------------------------
\draw[-] (\a,0,2*\a) -- (2*\a,\a,2*\a) -- (\a,2*\a,2*\a) -- (0,\a,2*\a) -- cycle;
\draw[-] (2*\a,0,\a) -- (2*\a,\a,0) -- (2*\a,2*\a,\a) -- (2*\a,\a,2*\a) -- cycle;
\draw[-] (\a,2*\a,2*\a) -- (2*\a,2*\a,\a) -- (\a,2*\a,0) -- (0,2*\a,\a) -- cycle;
%----- others edges -------
\draw[-] (\a,0,2*\a) -- (2*\a,0,\a) -- (\a,0,0) -- (2*\a,\a,0) -- (\a,2*\a,0);
%---nodes  --------------------
\node[xslant=0.5,yslant=-0.1,rotate=-10]  at (\a,\a,2*\a)            {\large{14}};
\node[xslant=0.5,yslant=-0.1,rotate=-5]   at (1.5*\a,0.3*\a,1.7*\a)  {\large{4}};
\node[xslant=0.1,rotate=1]                at (2*\a,\a,\a)            {\large{13}};
\node[xslant=-0.5,yslant=0.1]             at (1.7*\a,1.7*\a,1.7*\a)  {\large{1}};
\node[xslant=-0.6,yslant=0.6,rotate=10]   at (\a,2*\a,\a)            {\large{10}};
\node[xslant=0.5,yslant=-0.1,rotate=23]   at (1.7*\a,0.3*\a,0.3*\a)  {\large{3}};
\node[xslant=0.5,yslant=-0.1]             at (1.7*\a,1.7*\a,0.4*\a)  {\large{8}};
\end{tikzpicture}}
\end{document} I read some articles on projections in planes parallel to the coordinate planes. For exemple, I found this similar topic. However, in none of these articles was used the \ tdplotsetmaincoords command. Also, I could not find references about projecting texts in arbitrary planes. I would like to kindly ask some help to make the desired figures of the truncated numerated cube. Thank you very much.

• I'm afraid this looks like one for our Asymptote/Metapost gang. Feb 26, 2015 at 22:20
• @percusse: ...or PSTricks...
– Werner
Feb 26, 2015 at 22:35
• @Werner I always assume that it comes automatically just for fun anyway :) Feb 27, 2015 at 8:25
• Hmmm. It's fairly easy to define the points of a truncated cube for mp3d and draw it as a solid or a wireframe, but drawing numbers "stuck" to each face like that is not easy. Feb 27, 2015 at 13:00
• @Thurston. I thought about using an orthogonal transformation followed by a translation to write the numbers on the faces. But I have not found a mode of applying this in a text. Feb 28, 2015 at 1:38

To get better figures, I used the sloped option in the node command to be able to write a text tangent to a certain segment. For example, to put the 14 number in the top face of the first figure I used

\path (A) -- node[sloped] {14} (C);


where (A) and (C) are opposite vertices of this face. I did not know anything about this sloped option in the node command. I learned about it reading this topic.

To get the coordinates of the vertices of the second figure, I rotated de vertices of the truncated cube of the first figure. I learned about this reading this topic.

Manually I adjusted the positioning of each number on each face with xslant, yslant and rotation. It was very difficult to adjust these numbers and I believe that there should be more automatic way to project the numbers on the faces of the truncated cube.

I found in another topic a beautiful example of a pyramid with texts on their faces. Unfortunately this example is in PSTricks and I have no knowledge to be able to understand that code.

My tex code and the result obtained for the truncated cube with numbered faces are these. It was not 100%, but it is more or less acceptable. This answer does not end the discussion of this topic because there must be better solutions.

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows}
\usepackage{amsmath}

\begin{document}

\newcommand{\rotateRPY}% roll, pitch, yaw
{   \pgfmathsetmacro{\rollangle}{#1}
\pgfmathsetmacro{\pitchangle}{#2}
\pgfmathsetmacro{\yawangle}{#3}

% to what vector is the x unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newxx}{cos(\yawangle)*cos(\pitchangle)}
\pgfmathsetmacro{\newxy}{sin(\yawangle)*cos(\pitchangle)}
\pgfmathsetmacro{\newxz}{-sin(\pitchangle)}
\path (\newxx,\newxy,\newxz);
\pgfgetlastxy{\nxx}{\nxy};

% to what vector is the y unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newyx}{cos(\yawangle)*sin(\pitchangle)*sin(\rollangle)-sin(\yawangle)*cos(\rollangle)}
\pgfmathsetmacro{\newyy}{sin(\yawangle)*sin(\pitchangle)*sin(\rollangle)+ cos(\yawangle)*cos(\rollangle)}
\pgfmathsetmacro{\newyz}{cos(\pitchangle)*sin(\rollangle)}
\path (\newyx,\newyy,\newyz);
\pgfgetlastxy{\nyx}{\nyy};

% to what vector is the z unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newzx}{cos(\yawangle)*sin(\pitchangle)*cos(\rollangle)+ sin(\yawangle)*sin(\rollangle)}
\pgfmathsetmacro{\newzy}{sin(\yawangle)*sin(\pitchangle)*cos(\rollangle)-cos(\yawangle)*sin(\rollangle)}
\pgfmathsetmacro{\newzz}{cos(\pitchangle)*cos(\rollangle)}
\path (\newzx,\newzy,\newzz);
\pgfgetlastxy{\nzx}{\nzy};
}

\tikzset{RPY/.style={x={(\nxx,\nxy)},y={(\nyx,\nyy)},z={(\nzx,\nzy)}}}

\tdplotsetmaincoords{75}{105}
\centerline{
\begin{tikzpicture} [tdplot_main_coords]
\def\a{1.1}; %-- half of the edge of the cube
\coordinate (A) at (\a,0,2*\a);
\coordinate (B) at (2*\a,\a,2*\a);
\coordinate (C) at (\a,2*\a,2*\a);
\coordinate (D) at (0,\a,2*\a);
\coordinate (E) at (2*\a,0,\a);
\coordinate (F) at (2*\a,\a,0);
\coordinate (G) at (2*\a,2*\a,\a);
\coordinate (H) at (\a,2*\a,0);
\coordinate (I) at (0,2*\a,\a);
\coordinate (J) at (\a,0,0);
%----- triangular faces of the first figure -------
\draw[fill=lightgray!3!white,draw=none] (E) -- (A) -- (B) -- cycle;
\draw[fill=lightgray!3!white,draw=none] (B) -- (C) -- (G) -- cycle;
\draw[fill=lightgray!3!white,draw=none] (F) -- (G) -- (H) -- cycle;
\draw[fill=lightgray!3!white,draw=none] (E) -- (F) -- (J) -- cycle;
%-----faces with 4 edges ----------------------------------
\draw[fill=lightgray!2!white,draw=black,thick] (A) -- (B) -- (C) -- (D) -- cycle;
\draw[fill=lightgray!2!white,draw=black,thick] (E) -- (F) -- (G) -- (B) -- cycle;
\draw[fill=lightgray!2!white,draw=black,thick] (C) -- (G) -- (H) -- (I) -- cycle;
%----- others edges -------
\draw[-,thick] (A) -- (E) -- (J) -- (F) -- (H);
%---nodes  --------------------
\path (A) -- node[sloped,xslant=.6,yscale=0.9,xscale=1.1] {\large{\bf{14}}} (C);
\node[xslant=-0.5,yslant=0.2,scale=1.1]             at (1.7*\a,1.7*\a,1.65*\a)  {\large{\bf{1}}};
\node[xslant=0.5,yslant=-0.1,scale=1.05]             at (1.7*\a,1.7*\a,0.4*\a)  {\large{\bf{8}}};
\path ($(\a,0,2*\a)!0.3!(2*\a,0,\a)$) -- node[sloped,xslant=.2,yscale=1.2] {\large{\bf{4}}}     ($(2*\a,\a,2*\a)!0.3!(2*\a,0,\a)$);
\path  (2*\a,0,\a) -- node[sloped,xslant=-0.07,yscale=1.3,xscale=1.2] {\large{\bf{13}}} (2*\a,2*\a,\a);
\path  (2*\a,2*\a,\a) -- node[sloped,xslant=0.5] {\large{\bf{10}}} (0,2*\a,\a);
\path ($(\a,0,0)!0.3!(2*\a,0,\a)$) -- node[sloped,xslant=-0.4,rotate=12,xshift=-2pt,yscale=0.8] {\large{\bf{3}}}
($(2*\a,\a,0)!0.3!(2*\a,0,\a)$);
\end{tikzpicture} \ \ \ \ \ \
%--- SECOND FIGURE (on the right)
\tdplotsetmaincoords{75}{105}
\begin{tikzpicture} [tdplot_main_coords]
\def\a{1.05}; %-- half of the edge of the cube
\rotateRPY{-40}{-39}{15}
\begin{scope}[RPY]
\coordinate (A) at (2*\a,0,\a);
\coordinate (B) at (2*\a,\a,0);
\coordinate (C) at (2*\a,2*\a,\a);
\coordinate (D) at (2*\a,\a,2*\a);
\coordinate (E) at (\a,2*\a,2*\a);
\coordinate (F) at (\a,2*\a,0);
\coordinate (G) at (0,2*\a,\a);
\coordinate (H) at (\a,0,0);
\coordinate (I) at (0,\a,0);
\coordinate (J) at (\a,0,2*\a);
%----- triangular faces of the second figure -------
\draw[fill=lightgray!3!white,draw=none] (A) -- (J) -- (D) -- cycle;
\draw[fill=lightgray!3!white,draw=none] (D) -- (E) -- (C) -- cycle;
\draw[fill=lightgray!3!white,draw=none] (C) -- (F) -- (B) -- cycle;
\draw[fill=lightgray!3!white,draw=none] (A) -- (B) -- (H) -- cycle;
%-----faces with 4 edges ----------------------------------
\draw[fill=lightgray!2!white,draw=black,thick] (A)  -- (B) -- (C) -- (D) -- cycle;
\draw[fill=lightgray!2!white,draw=black,thick] (E) -- (C) -- (F) -- (G) -- cycle;
\draw[fill=lightgray!2!white,draw=black,thick] (H) -- (B) -- (F) -- (I) -- cycle;
%---- other edges
\draw[-,black,thick] (H) -- (A) -- (J) -- (D) -- (E);
%---nodes  --------------------
\path ($(A)!0.5!(B)$)  -- node[sloped,xslant=0.02,yscale=1.3,xscale=1.2] {\large{\bf{11}}} ($(D)!0.5!(C)$);
\path (H)  -- node[sloped,xslant=0.2,rotate=-10,xscale=1.1,yscale=1.2] {\large{\bf{7}}} (F);
\path (C)  -- node[sloped,yslant=-0.35,xslant=-0.1,rotate=-5,yshift=1pt] {\large{\bf{12}}} (G);
\path (A)  -- node[sloped,xslant=-0.1,yslant=0.1,xshift=-8pt,yshift=1pt, rotate=26,yscale=1.4,xscale=1.1] {\large{\bf{3}}} ($(H)!0.5!(B)$);
\path ($(B)!0.4!(F)$)  -- node[sloped,xslant=0.1,yscale=1.25,xscale=1.2,yshift=1pt] {\large{\bf{2}}} ($(C)!0.4!(F)$);
\path ($(E)!0.6!(D)$)  -- node[sloped,xslant=0.3,rotate=5,yscale=1.3,xscale=1.1,xshift=2pt] {\large{\bf{5}}} ($(E)!0.6!(C)$);
\path ($(J)!0.5!(A)$)  -- node[sloped,xslant=-0.4,xscale=1.1,yscale=0.6] {\bf{8}} ($(J)!0.5!(D)$);
\end{scope}
\end{tikzpicture}}

\end{document} 