![Tikz: textura de caras de cubo usando imagen png](https://rvso.com/image/286981/Tikz%3A%20textura%20de%20caras%20de%20cubo%20usando%20imagen%20png.png)
Me gustaría dibujar un cubo usando Tikz con algunas caras del cubo que tengan una textura (la textura sería una imagen PNG)
mi código actual es el siguiente:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{3d,calc}
\tikzset{persp/.style={scale=3.0,x={(-0.8cm,-0.4cm)},y={(0.8cm,-0.4cm)}, z={(0cm,1cm)}},points/.style={fill=white,draw=black,thick}}
\begin{document}
\begin{tikzpicture}[persp]\def\i{-15}
\pgfmathparse{cos(\i)}\let\ci\pgfmathresult
\pgfmathparse{sin(\i)}\let\si\pgfmathresult
\coordinate (Ocube) at (0,0,0);
\coordinate (Xcube) at (\ci,\si,0);
\coordinate (Ycube) at (-\si,\ci,0);
\coordinate (Zcube) at (0,0,1);
\coordinate (C0) at ($(Ocube)-(Xcube)-(Ycube)-(Zcube)$);
\coordinate (C1) at ($(Ocube)+(Xcube)-(Ycube)-(Zcube)$);
\coordinate (C2) at ($(Ocube)-(Xcube)+(Ycube)-(Zcube)$);
\coordinate (C3) at ($(Ocube)+(Xcube)+(Ycube)-(Zcube)$);
\coordinate (C4) at ($(Ocube)-(Xcube)-(Ycube)+(Zcube)$);
\coordinate (C5) at ($(Ocube)+(Xcube)-(Ycube)+(Zcube)$);
\coordinate (C6) at ($(Ocube)-(Xcube)+(Ycube)+(Zcube)$);
\coordinate (C7) at ($(Ocube)+(Xcube)+(Ycube)+(Zcube)$);
\fill[black!20, draw=black, dashed,opacity=0.3] (C0)--(C1)--(C3)--(C2)--cycle;
\fill[black!20, draw=black, dashed,opacity=0.3] (C0)--(C1)--(C5)--(C4)--cycle;
\fill[black!20, draw=black, dashed,opacity=0.3] (C0)--(C2)--(C6)--(C4)--cycle;
\fill[black!20, draw=black, thick,opacity=0.3] (C4)--(C5)--(C7)--(C6)--cycle;
\fill[black!20, draw=black, thick,opacity=0.3] (C2)--(C3)--(C7)--(C6)--cycle;
\fill[black!20, draw=black, thick,opacity=0.3] (C1)--(C3)--(C7)--(C5)--cycle;
\coordinate (Q0) at ($(Ocube)-.8*(Xcube)+(Ycube)-.8*(Zcube)$);
\coordinate (Q1) at ($(Ocube)+.8*(Xcube)+(Ycube)-.8*(Zcube)$);
\coordinate (Q2) at ($(Ocube)-.8*(Xcube)+(Ycube)+.8*(Zcube)$);
\coordinate (Q3) at ($(Ocube)+.8*(Xcube)+(Ycube)+.8*(Zcube)$);
\fill[white!20, draw=black, thick,opacity=0.3] (Q0)--(Q1)--(Q3)--(Q2)--cycle;
\end{tikzpicture}
\end{document}
En la última línea, en lugar de llenar un color blanco (¡blanco!20), me gustaría dibujar la imagen "face.png". Este dibujo debe distorsionarse para que se ajuste al rostro de manera realista.
¿Alguien podría ayudarme a hacer eso?
Respuesta1
No es exactamente una respuesta a la pregunta, pero es divertido.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
\draw[yellow,yslant=0.5] (0,0) rectangle (2,2);
\node[yslant=0.5,anchor=center,opacity=0.3] at (1,1.5) {\includegraphics[width=2cm,height=2cm]{example-image-a}};
\draw[magenta,yslant=-0.5] (-2,2) rectangle (0,0);
\node[yslant=-0.5,anchor=center,opacity=0.3] at (-1,1.5) {\includegraphics[width=2cm,height=2cm]{example-image-b}};
\begin{scope}[on background layer]
\draw[orange,yslant=-0.5] (0,2) rectangle (2,4);
\node[yslant=-0.5,anchor=center,xshift=0cm,yshift=1cm,opacity=0.3] at (1,1.5) {\includegraphics[width=2cm,height=2cm]{example-image-b}};
\draw[green,yslant=0.5,,xshift=-2cm,yshift=2cm] (0,0) rectangle (2,2);
\node[yslant=0.5,anchor=center,xshift=-2cm,yshift=2cm,opacity=0.3] at (1,1.5) {\includegraphics[width=2cm,height=2cm]{example-image-a}};
\draw[blue,yslant=-0.5,xslant=1] (-2,0) rectangle (0,2);
\node[yslant=-0.5,anchor=center,xshift=0cm,yshift=2cm,xslant=1,opacity=0.3] at (-0,-1) {\includegraphics[width=2cm,height=2cm]{example-image-a}};
\end{scope}
\draw[red,yslant=-0.5,xslant=1] (-4,2) rectangle (-2,4);
\node[yslant=-0.5,anchor=center,xshift=0cm,yshift=4cm,xslant=1,opacity=0.3] at (-0,-1) {\includegraphics[width=2cm,height=2cm]{example-image-a}};
\end{tikzpicture}
\end{document}
Respuesta2
Hay varias preguntas en el sitio que abordan cómo rellenar una forma con una imagen en TikZ, por ejemplo:
- TikZ: Dibujar hexágonos regulares con imágenes en su interior
- Cómo recortar una imagen externa dentro de una elipse
Podemos adaptar esas soluciones a su forma 3D. Solemos \clip
restringirlo al cuadrado frontal del cubo, luego agregamos la imagen y finalmente dibujamos el borde a su alrededor.
He reemplazado la línea:
\fill[white!20, draw=black, thick,opacity=0.3] (Q0)--(Q1)--(Q3)--(Q2)--cycle;
con
\def\frontsquare{(Q0)--(Q1)--(Q3)--(Q2)--cycle}
\begin{scope}
\clip \frontsquare;
\node {\includegraphics{grass.jpg}};
\end{scope}
\draw[black, thick] \frontsquare;
Primero defino \frontsquare
el área que deseas llenar. Lo \clip
contenido en el alcance restringe todo lo demás que atraemos dentro de esa área, hasta \end{scope}
. Cuando uso \includegraphics
para agregar una imagen, solo la parte de la imagen que está dentro del cuadrado frontal. Luego, el \draw
comando agrega un borde.
Así es como se ve el cubo resultante:
y aquí está el código completo:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{3d,calc}
\tikzset{persp/.style={scale=3.0,x={(-0.8cm,-0.4cm)},y={(0.8cm,-0.4cm)}, z={(0cm,1cm)}},points/.style={fill=white,draw=black,thick}}
\begin{document}
\begin{tikzpicture}[persp]\def\i{-15}
\pgfmathparse{cos(\i)}\let\ci\pgfmathresult
\pgfmathparse{sin(\i)}\let\si\pgfmathresult
\coordinate (Ocube) at (0,0,0);
\coordinate (Xcube) at (\ci,\si,0);
\coordinate (Ycube) at (-\si,\ci,0);
\coordinate (Zcube) at (0,0,1);
\coordinate (C0) at ($(Ocube)-(Xcube)-(Ycube)-(Zcube)$);
\coordinate (C1) at ($(Ocube)+(Xcube)-(Ycube)-(Zcube)$);
\coordinate (C2) at ($(Ocube)-(Xcube)+(Ycube)-(Zcube)$);
\coordinate (C3) at ($(Ocube)+(Xcube)+(Ycube)-(Zcube)$);
\coordinate (C4) at ($(Ocube)-(Xcube)-(Ycube)+(Zcube)$);
\coordinate (C5) at ($(Ocube)+(Xcube)-(Ycube)+(Zcube)$);
\coordinate (C6) at ($(Ocube)-(Xcube)+(Ycube)+(Zcube)$);
\coordinate (C7) at ($(Ocube)+(Xcube)+(Ycube)+(Zcube)$);
\fill[black!20, draw=black, dashed,opacity=0.3] (C0)--(C1)--(C3)--(C2)--cycle;
\fill[black!20, draw=black, dashed,opacity=0.3] (C0)--(C1)--(C5)--(C4)--cycle;
\fill[black!20, draw=black, dashed,opacity=0.3] (C0)--(C2)--(C6)--(C4)--cycle;
\fill[black!20, draw=black, thick,opacity=0.3] (C4)--(C5)--(C7)--(C6)--cycle;
\fill[black!20, draw=black, thick,opacity=0.3] (C2)--(C3)--(C7)--(C6)--cycle;
\fill[black!20, draw=black, thick,opacity=0.3] (C1)--(C3)--(C7)--(C5)--cycle;
\coordinate (Q0) at ($(Ocube)-.8*(Xcube)+(Ycube)-.8*(Zcube)$);
\coordinate (Q1) at ($(Ocube)+.8*(Xcube)+(Ycube)-.8*(Zcube)$);
\coordinate (Q2) at ($(Ocube)-.8*(Xcube)+(Ycube)+.8*(Zcube)$);
\coordinate (Q3) at ($(Ocube)+.8*(Xcube)+(Ycube)+.8*(Zcube)$);
\def\frontsquare{(Q0)--(Q1)--(Q3)--(Q2)--cycle}
\begin{scope}
\clip \frontsquare;
\node {\includegraphics{grass.jpg}};
\end{scope}
\draw[black, thick] \frontsquare;
\end{tikzpicture}
\end{document}