# How may I color four sides of a cube?

I want to color four sides of a cube for an illustration. Let the corners of the cube be designated by the eight Cartesian coordinates $(0,0,0)$, $(0,0,1)$, $(0,1,0)$, $(0,1,1)$, $(1,0,0)$, $(1,0,1)$, $(1,1,0)$, $(1,1,1)$. The two sides of the cube that contain both of the corners $(0,1,1)$ and $(1,1,1)$ are to be blank. The side of the cube that contains both $(0,1,1)$ and $(0,0,1)$ and does not contain $(1,1,1)$ should be blue. The side of the cube that contains both $(1,1,1)$ and $(1,0,1)$ and does not contain $(0,1,1)$ should be red. The side of the cube that contains all of $(0,1,0)$, $(1,1,0)$, $(0,0,0)$, $(1,0,0)$ should be green. The side of the cube that contains all of $(0,0,1)$, $(1,0,1)$, $(0,0,0)$, $(1,0,0)$ should be yellow.

If we relate the desired coloring scheme to the attached picture with the coloring scheme of a Rubik's Cube, the color white of the RC is replaced by blank, the color green of the RC is replaced by blank, the color red of the RC is kept, the color blue of the RC is replaced by yellow, the color orange of the RC is replaced by blue and the color yellow of the RC is replaced by green. It is nice if the drawing of the cube has a perspective so that the four colors can be seen and reproduced in print, and it is nice if there is some space for writing a caption.

To this confer my question Can we color and rotate a cube? which asks for a dynamical representation.

• One picture is worth of thousand mathjax – percusse Sep 28 '15 at 17:56
• @percusse Does it help? – Sapiens Sep 28 '15 at 18:16

The present code should solve your problem:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
[
scale=6.0,
very thick,
line join=round,
y={(-1cm,0.5cm)},
x={(1cm,0.5cm)},
z={(0cm,1cm)},
]

\coordinate (A1) at (0,0,0);
\coordinate (A2) at (0,1,0);
\coordinate (A3) at (1,1,0);
\coordinate (A4) at (1,0,0);
\coordinate (B1) at (0,0,1);
\coordinate (B2) at (0,1,1);
\coordinate (B3) at (1,1,1);
\coordinate (B4) at (1,0,1);

\fill[yellow] (A2) -- (A3) -- (B3) -- (B2) -- cycle;
\fill[green]  (A2) -- (A3) -- (A4) -- (A1) -- cycle;
\fill[red]    (A3) -- (B3) -- (B4) -- (A4) -- cycle;
\fill[blue]   (A1) -- (A2) -- (B2) -- (B1) -- cycle;

\draw (A2) -- (A1) -- (A4);
\draw (B2) -- (B1) -- (B4) -- (B3) -- cycle;
\draw (A1) -- (B1);
\draw (A2) -- (B2);
\draw (A4) -- (B4);

\draw[thin] (A3) -- (B3);
\draw[thin] (A3) -- (A4);
\end{tikzpicture}
\caption{This is my colored box.}
\end{figure}
\end{document} Disclaimer: This answer is based on an answer by Gonzalo Medina (@GonzaloMedina) that was deleted after this answer was accepted. The code was basically written by him, I only made minor modifications in order to more precisely answer the present question.

• Thanks! This is quite it, except that in my scheme I prefer to switch your yellow with green and your blue with red. – Sapiens Sep 28 '15 at 21:27
• Answer is updated according to your preferences now. – Karl Yngve Lervåg Sep 28 '15 at 21:51
• Is it possible to rotate the cube +20° around the vertical axis that divide the blue and yellow side and -10° around the axis common to the red and green side? We should avoid any color mixing. – Sapiens Sep 29 '15 at 1:57

This can be easily done with tikz-3dplot. You can change the color of each side as you wish. Also, you can see the cube from different angles (i.e. change the view angles in the code). Moreover, you can carry out the rotation around an arbitrary axis (i.e. see my answer my answer).

\documentclass[border={10}]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}

\tdplotsetmaincoords{60}{125} % view angles
\tdplotsetrotatedcoords{0}{0}{0}
\begin{document}

\begin{tikzpicture}
[%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
scale=5,tdplot_rotated_coords,
cube/.style={line width=3pt,black},
grid/.style={very thin,gray},
axis/.style={->,blue,line width=3pt,>=stealth},
]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%draw a grid in the x-y plane
\foreach \x in {-0.5,0,...,2.5}
\foreach \y in {-0.5,0,...,2.5}
{
\draw[grid] (\x,-0.5) -- (\x,2.5);
\draw[grid] (-0.5,\y) -- (2.5,\y);
}

%draw the main coordinate frame axes
\draw[axis,tdplot_main_coords] (0,0,0) -- (3.5,0,0) node[anchor=north]{$x$};
\draw[axis,tdplot_main_coords] (0,0,0) -- (0,3.5,0) node[anchor=north]{$y$};
\draw[axis,tdplot_main_coords] (0,0,0) -- (0,0,3.5) node[anchor=west] {$z$};

%draw the cube
\draw[cube,fill=blue]                        (0,0,0) -- (0,2,0) -- (2,2,0) -- (2,0,0) -- cycle;
\draw[cube,fill=red]                         (0,0,0) -- (0,2,0) -- (0,2,2) -- (0,0,2) -- cycle;
\draw[cube,fill=green!20]                    (0,0,0) -- (2,0,0) -- (2,0,2) -- (0,0,2) -- cycle;
\draw[cube,fill=yellow!20]                   (0,0,2) -- (2,0,2) -- (2,2,2) -- (0,2,2) -- cycle;
\draw[cube,fill=black!30!green]              (2,2,2) -- (0,2,2) -- (0,2,0) -- (2,2,0) -- cycle;
\draw[cube,fill=black!30!yellow,opacity=0.7] (2,0,0) -- (2,2,0) -- (2,2,2) -- (2,0,2) -- cycle;
\end{tikzpicture}

\end{document} • Thanks! It would be very interesting to me if your answer could be combined with that in the answer of Karl Yngve Lervåg to rotate the cube, so colored as his, as I suggest in my last comment to him. – Sapiens Sep 29 '15 at 14:03
• @Karl Yngve Lervåg Maybe this is something that also Karl Yngve Lervåg can pick up on? – Sapiens Sep 29 '15 at 15:16