Tentando desenhar um cubo 3x3x3 colorido usando o tikzpicture

Tentando desenhar um cubo 3x3x3 colorido usando o tikzpicture

Estou tentando desenhar o cubo de Rubik em LateX e usei o código abaixo. Tudo parece funcionar, exceto a face frontal, que por algum motivo não está certa. Alguém conhece uma solução para este problema? Estou usando o pacote tikz e xcolor.

Aqui está o que acontece

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

Responder1

Seu problema é que você desenhou a face posterior, não a frontal. Você pode ver isso se desenhar um diagrama simples mostrando os vetores unitários:

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

insira a descrição da imagem aqui

Como o eixo z está apontando para fora da página, a face vermelha e branca cobre a face azul, com as coordenadas que você usou.

Portanto, uma maneira simples de corrigir isso é inverter o vetor da unidade z. Por padrão é (-3.85mm,-3.85mm), então você só precisa fazer

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

e seu diagrama ficará parecido

insira a descrição da imagem aqui

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

Responder2

Tudo o que Torbjorn diz está correto, assim como sua solução, mas esse código produz o mesmo resultado e é muito mais curto.

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

informação relacionada