Intentando dibujar un cubo coloreado de 3x3x3 usando tikzpicture

Intentando dibujar un cubo coloreado de 3x3x3 usando tikzpicture

Estoy intentando dibujar el cubo de Rubik en LateX y he utilizado el siguiente código. Todo parece funcionar excepto la cara frontal, que por alguna razón no está bien. ¿Alguien sabe una solución para este problema? Estoy usando el paquete tikz y xcolor.

Esto es lo que sucede

\begin{tikzpicture}
\coordinate (O) at (0,0,0);
\coordinate (A) at (1,0,0);
\coordinate (B) at (2,0,0);
\coordinate (C) at (3,0,0);
\coordinate (D) at (0,1,0);
\coordinate (G) at (1,1,0);
\coordinate (L) at (2,1,0);
\coordinate (N) at (3,1,0);
\coordinate (E) at (0,2,0);
\coordinate (J) at (1,2,0);
\coordinate (H) at (2,2,0);
\coordinate (P) at (3,2,0);
\coordinate (F) at (0,3,0);
\coordinate (K) at (1,3,0);
\coordinate (M) at (2,3,0);
\coordinate (I) at (3,3,0);
\coordinate (Q) at (3,0,1);
\coordinate (R) at (3,0,2);
\coordinate (S) at (3,0,3);
\coordinate (T) at (3,1,1);
\coordinate (U) at (3,1,2);
\coordinate (V) at (3,1,3);
\coordinate (W) at (3,2,1);
\coordinate (X) at (3,2,2);
\coordinate (Y) at (3,2,3);
\coordinate (Z) at (3,3,1);
\coordinate (AA) at (3,3,2);
\coordinate (BB) at (3,3,3);
\coordinate (CC) at (0,3,1);
\coordinate (DD) at (1,3,1);
\coordinate (EE) at (2,3,1);
\coordinate (FF) at (0,3,2);
\coordinate (GG) at (1,3,2);
\coordinate (HH) at (2,3,2);
\coordinate (II) at (0,3,3);
\coordinate (JJ) at (1,3,3);
\coordinate (KK) at (2,3,3);

\draw[black,fill=blue!80] (O) -- (A) -- (G) -- (D) -- cycle;
\draw[black,fill=blue!80] (A) -- (B) -- (L) -- (G) -- cycle;
\draw[black,fill=blue!80] (B) -- (C) -- (N) -- (L) -- cycle;
\draw[black,fill=blue!80] (D) -- (G) -- (J) -- (E) -- cycle;
\draw[black,fill=blue!80] (G) -- (L) -- (H) -- (J) -- cycle;
\draw[black,fill=blue!80] (L) -- (N) -- (P) -- (H) -- cycle;
\draw[black,fill=blue!80] (E) -- (J) -- (K) -- (F) -- cycle;
\draw[black,fill=blue!80] (J) -- (H) -- (M) -- (K) -- cycle;
\draw[black,fill=blue!80] (H) -- (P) -- (I) -- (M) -- cycle;

\draw[black,fill=white!80] (C) -- (Q) -- (T) -- (N) -- cycle;
\draw[black,fill=white!80] (Q) -- (R) -- (U) -- (T) -- cycle;
\draw[black,fill=white!80] (R) -- (S) -- (V) -- (U) -- cycle;
\draw[black,fill=white!80] (N) -- (T) -- (W) -- (P) -- cycle;
\draw[black,fill=white!80] (T) -- (U) -- (X) -- (W) -- cycle;
\draw[black,fill=white!80] (U) -- (V) -- (Y) -- (X) -- cycle;
\draw[black,fill=white!80] (P) -- (W) -- (Z) -- (I) -- cycle;
\draw[black,fill=white!80] (W) -- (X) -- (AA) -- (Z) -- cycle;
\draw[black,fill=white!80] (X) -- (Y) -- (BB) -- (AA) -- cycle;

\draw[black,fill=red!80] (F) -- (K) -- (DD) -- (CC) -- cycle;
\draw[black,fill=red!80] (K) -- (M) -- (EE) -- (DD) -- cycle;
\draw[black,fill=red!80] (M) -- (I) -- (Z) -- (EE) -- cycle;
\draw[black,fill=red!80] (CC) -- (DD) -- (GG) -- (FF) -- cycle;
\draw[black,fill=red!80] (DD) -- (EE) -- (HH) -- (GG) -- cycle;
\draw[black,fill=red!80] (EE) -- (Z) -- (AA) -- (HH) -- cycle;
\draw[black,fill=red!80] (FF) -- (GG) -- (JJ) -- (II) -- cycle;
\draw[black,fill=red!80] (GG) -- (HH) -- (KK) -- (JJ) -- cycle;
\draw[black,fill=red!80] (HH) -- (AA) -- (BB) -- (KK) -- cycle;

\end{tikzpicture}

Respuesta1

Tu problema es que has dibujado la cara trasera, no la frontal. Puedes ver que si dibujas un diagrama simple que muestra los vectores unitarios:

\begin{tikzpicture}[->]
\draw (0,0,0) -- (1,0,0) node[right]{$x$};
\draw (0,0,0) -- (0,1,0) node[right]{$y$};
\draw (0,0,0) -- (0,0,1) node[right]{$z$};
\end{tikzpicture}

ingrese la descripción de la imagen aquí

Debido a que el eje z apunta hacia afuera de la página, la cara roja y blanca cubre la cara azul, con las coordenadas que has utilizado.

Entonces, una forma sencilla de solucionar este problema es invertir el vector unitario z. Por defecto lo es (-3.85mm,-3.85mm), así que sólo tienes que hacer

\begin{tikzpicture}[z={(3.85mm,3.85mm)}]

y tu diagrama se verá así

ingrese la descripción de la imagen aquí

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[z={(3.85mm,3.85mm)}]
\coordinate (O) at (0,0,0);
\coordinate (A) at (1,0,0);
\coordinate (B) at (2,0,0);
\coordinate (C) at (3,0,0);
\coordinate (D) at (0,1,0);
\coordinate (G) at (1,1,0);
\coordinate (L) at (2,1,0);
\coordinate (N) at (3,1,0);
\coordinate (E) at (0,2,0);
\coordinate (J) at (1,2,0);
\coordinate (H) at (2,2,0);
\coordinate (P) at (3,2,0);
\coordinate (F) at (0,3,0);
\coordinate (K) at (1,3,0);
\coordinate (M) at (2,3,0);
\coordinate (I) at (3,3,0);
\coordinate (Q) at (3,0,1);
\coordinate (R) at (3,0,2);
\coordinate (S) at (3,0,3);
\coordinate (T) at (3,1,1);
\coordinate (U) at (3,1,2);
\coordinate (V) at (3,1,3);
\coordinate (W) at (3,2,1);
\coordinate (X) at (3,2,2);
\coordinate (Y) at (3,2,3);
\coordinate (Z) at (3,3,1);
\coordinate (AA) at (3,3,2);
\coordinate (BB) at (3,3,3);
\coordinate (CC) at (0,3,1);
\coordinate (DD) at (1,3,1);
\coordinate (EE) at (2,3,1);
\coordinate (FF) at (0,3,2);
\coordinate (GG) at (1,3,2);
\coordinate (HH) at (2,3,2);
\coordinate (II) at (0,3,3);
\coordinate (JJ) at (1,3,3);
\coordinate (KK) at (2,3,3);

\draw[black,fill=blue!80] (O) -- (A) -- (G) -- (D) -- cycle;
\draw[black,fill=blue!80] (A) -- (B) -- (L) -- (G) -- cycle;
\draw[black,fill=blue!80] (B) -- (C) -- (N) -- (L) -- cycle;
\draw[black,fill=blue!80] (D) -- (G) -- (J) -- (E) -- cycle;
\draw[black,fill=blue!80] (G) -- (L) -- (H) -- (J) -- cycle;
\draw[black,fill=blue!80] (L) -- (N) -- (P) -- (H) -- cycle;
\draw[black,fill=blue!80] (E) -- (J) -- (K) -- (F) -- cycle;
\draw[black,fill=blue!80] (J) -- (H) -- (M) -- (K) -- cycle;
\draw[black,fill=blue!80] (H) -- (P) -- (I) -- (M) -- cycle;

\draw[black,fill=white!80] (C) -- (Q) -- (T) -- (N) -- cycle;
\draw[black,fill=white!80] (Q) -- (R) -- (U) -- (T) -- cycle;
\draw[black,fill=white!80] (R) -- (S) -- (V) -- (U) -- cycle;
\draw[black,fill=white!80] (N) -- (T) -- (W) -- (P) -- cycle;
\draw[black,fill=white!80] (T) -- (U) -- (X) -- (W) -- cycle;
\draw[black,fill=white!80] (U) -- (V) -- (Y) -- (X) -- cycle;
\draw[black,fill=white!80] (P) -- (W) -- (Z) -- (I) -- cycle;
\draw[black,fill=white!80] (W) -- (X) -- (AA) -- (Z) -- cycle;
\draw[black,fill=white!80] (X) -- (Y) -- (BB) -- (AA) -- cycle;

\draw[black,fill=red!80] (F) -- (K) -- (DD) -- (CC) -- cycle;
\draw[black,fill=red!80] (K) -- (M) -- (EE) -- (DD) -- cycle;
\draw[black,fill=red!80] (M) -- (I) -- (Z) -- (EE) -- cycle;
\draw[black,fill=red!80] (CC) -- (DD) -- (GG) -- (FF) -- cycle;
\draw[black,fill=red!80] (DD) -- (EE) -- (HH) -- (GG) -- cycle;
\draw[black,fill=red!80] (EE) -- (Z) -- (AA) -- (HH) -- cycle;
\draw[black,fill=red!80] (FF) -- (GG) -- (JJ) -- (II) -- cycle;
\draw[black,fill=red!80] (GG) -- (HH) -- (KK) -- (JJ) -- cycle;
\draw[black,fill=red!80] (HH) -- (AA) -- (BB) -- (KK) -- cycle;

\end{tikzpicture}
\end{document}

Respuesta2

Todo lo que dice Torbjorn es correcto, al igual que su solución, pero este código produce el mismo resultado y es mucho más corto.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[fill=blue!80] (0,0,3)--(3,0,3)--(3,3,3)--(0,3,3)--cycle;
\draw[fill=white!80] (3,0,0) -- (3,3,0)--(3,3,3)--(3,0,3)--cycle;
\draw[fill=red!80] (3,3,0) -- (3,3,3)--(0,3,3)--(0,3,0)--cycle;
\foreach \x in {1,2}
 {
\draw(3,0,\x)--(3,3,\x); 
\draw(3,\x,0)--(3,\x,3); 
\draw(0,\x,3)--(3,\x,3); 
\draw(\x,0,3)--(\x,3,3); 
\draw(\x,3,0)--(\x,3,3); 
\draw(0,3,\x)--(3,3,\x); 
}
\end{tikzpicture}
\end{document}

información relacionada