7

I know one can write (and even draw) on a face of a solid following the perspective, like in

writing with perspective

obtained from this code that draws a fake (2-dim) representation of the cube:

\documentclass[tikz,border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}

\begin{scope}[every node/.append style={yslant=-0.5},yslant=-0.5] \shade[right color=gray!10, left color=black!50] (0,0) rectangle +(3,3); \node at (1.5,1.5) {\Huge 2}; \end{scope}

\begin{scope}[every node/.append style={yslant=0.5},yslant=0.5] \shade[right color=gray!70,left color=gray!10] (3,-3) rectangle +(3,3); \node at (4.5,-1.5) {\Huge 1}; \end{scope}

\begin{scope}[every node/.append style={yslant=0.5,xslant=-1},yslant=0.5,xslant=-1] \shade[bottom color=gray!10, top color=black!80] (6,3) rectangle +(-3,-3); \node at (4.5,1.5) {\Huge 3}; \end{scope}

\end{tikzpicture} \end{document}

Is it possible to drape an image like:

world map wikipedia

on top of, lets say, two faces of a cube?

I am aware of draping on a plot but can't quite be applied here.

  • 2
    Couldn't you just \includegraphics the picture instead of a digit in your slanted node? It's just a matter of resizing and trimming than (which could be automated a bit surely}. – Qrrbrbirlbel Oct 22 '22 at 22:12
  • @Qrrbrbirlbel Could you elaborate on the possible solution? A simple use of \includegraphics would end up in an interminable hand ajustements of coordinates of the rectalgular image to fit the coordinates of the TikZ figure, just like the solution posted below. – TeX Apprentice Oct 23 '22 at 23:11

1 Answers1

10
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}[inner sep=0pt, outer sep=0pt, line join=bevel]
\node[draw, ultra thick, anchor=north east, yslant=-0.5] {\includegraphics[viewport={3.2cm 1.6cm 8.2cm 6.6cm}, clip]{example-image-a}};
\node[draw, ultra thick, anchor=north west, yslant=0.5] {\includegraphics[viewport={3.2cm 1.6cm 8.2cm 6.6cm}, clip]{example-image-b}};
\node[draw, ultra thick, anchor=south west, yslant=0.5, xslant=-1] {\includegraphics[viewport={3.2cm 1.6cm 8.2cm 6.6cm}, clip]{example-image-c}};
\end{tikzpicture}
\end{document}

Dice with image on the sides

Edit:

With tikz-3dplot instead of manual slant you can change the view angles in \tdplotsetmaincoords{80}{110}

\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{80}{110}
\begin{tikzpicture}[tdplot_main_coords, inner sep=0pt, outer sep=0pt, line join=bevel]
\node[draw, ultra thick, transform shape, canvas is yz plane at x=1] {\includegraphics[scale=0.4, viewport={3.2cm 1.6cm 8.2cm 6.6cm}, clip]{example-image-a}};
\node[draw, ultra thick, transform shape, canvas is xz plane at y=1] {\includegraphics[scale=0.4, viewport={3.2cm 1.6cm 8.2cm 6.6cm}, clip]{example-image-b}};
\node[draw, ultra thick, transform shape, canvas is xy plane at z=1] {\includegraphics[scale=0.4, viewport={3.2cm 1.6cm 8.2cm 6.6cm}, clip]{example-image-c}};
\end{tikzpicture}
\end{document}  

Dice with images on sides

Edit:

\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz-3dplot}
\usepackage{adjustbox}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords, inner sep=0pt, outer sep=0pt, line join=bevel]
\node[draw, thick, transform shape, canvas is yz plane at x=1]            {\adjustbox{trim={0.250\width} {0.333\height} {0.500\width} {0.333\height}, clip}{\includegraphics[width=8cm]{ulvyP.png}}};
\node[draw, thick, transform shape, canvas is xz plane at y=1, xscale=-1] {\adjustbox{trim={0.500\width} {0.333\height} {0.250\width} {0.333\height}, clip}{\includegraphics[width=8cm]{ulvyP.png}}};
\node[draw, thick, transform shape, canvas is xy plane at z=1, rotate=90] {\adjustbox{trim={0.250\width} {0.666\height} {0.500\width} {0.000\height}, clip}{\includegraphics[width=8cm]{ulvyP.png}}};
\end{tikzpicture}
\end{document}  

Cube with earth image on sides

Image source: https://gis.stackexchange.com/questions/392282/why-does-cubemap-projection-preserve-lines-of-longitude-but-not-latitude

  • +1: Can you add some rational? – Dr. Manuel Kuehner Oct 23 '22 at 02:44
  • @hpekristiansen In this way one has to take care of the viewport, cropping, etc ... Can TikZ map tghe four corners of the image into the four corners of the quadrilateral? – TeX Apprentice Oct 23 '22 at 22:49
  • What quadrilateral is that? I only see three rhombs(squares) and a hexagon. I do not know what mapping you mean. – hpekristiansen Oct 24 '22 at 02:26
  • The mapping from the square (or rectangle) with the image to the rhomb that makes up the image of the cube. If that mapping could be built in TikZ it would eliminate the need for controlling \includegraphics parameters. – TeX Apprentice Oct 24 '22 at 04:08