0

I am looking for a solution to draw on the faces of a cube (or similar 3d plane surfaces with perspective) preferably with the means of tikz. The basics are given in Tikz : texture cube faces using png image but this does not solve the problem of distorting the image. I am a 100% sure, that I have seen such a solution on the web, 95% it was on SE with a Tux on one face, but I cannot find it anymore, hence if you can lead me to that question or to a solution, that would be great!

TobiBS
  • 5,240
  • 1
    Can you please explain what "the problem of distorting the image" is? –  Jun 01 '20 at 13:14

1 Answers1

2

This is merely an attempt to clarify the question. There is a difference between perspective projections and orthographic projections. For the latter it is almost trivial to project the a picture on a cube.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{perspective,3d}
\tikzset{pics/perspective cuboid/.style={code={
    \tikzset{perspective cuboid/.cd,#1}%
    \def\pv##1{\pgfkeysvalueof{/tikz/perspective cuboid/##1}}% 
    \draw (tpp cs:x=-\pv{a},y=-\pv{a},z=-\pv{a})
     -- (tpp cs:x=\pv{a},y=-\pv{a},z=-\pv{a})
     -- (tpp cs:x=\pv{a},y=\pv{a},z=-\pv{a})
     -- (tpp cs:x=-\pv{a},y=\pv{a},z=-\pv{a}) -- cycle
     (tpp cs:x=-\pv{a},y=-\pv{a},z=\pv{a}) edge (tpp cs:x=-\pv{a},y=-\pv{a},z=-\pv{a})
     -- (tpp cs:x=\pv{a},y=-\pv{a},z=\pv{a}) edge (tpp cs:x=\pv{a},y=-\pv{a},z=-\pv{a})
     -- (tpp cs:x=\pv{a},y=\pv{a},z=\pv{a}) edge (tpp cs:x=\pv{a},y=\pv{a},z=-\pv{a})
     -- (tpp cs:x=-\pv{a},y=\pv{a},z=\pv{a}) edge (tpp cs:x=-\pv{a},y=\pv{a},z=-\pv{a})     
     -- cycle;     
    }},perspective cuboid/.cd,a/.initial=1}
\begin{document}
\begin{tikzpicture}[3d view,perspective]
  \pic{perspective cuboid};
\end{tikzpicture}

\begin{tikzpicture}[3d view] \pic{perspective cuboid}; \begin{scope}[canvas is xz plane at y=-1,transform shape] \node{\includegraphics[width=2cm,height=2cm]{example-image-duck}}; \end{scope} \end{tikzpicture}

\end{document}

enter image description here

Can one project an image on a face of the first cube, which is drawn in perspective projection using the perspective library? Yes, one can. Some of the relevant posts are

As you can see, none of them is trivial, and for complex images the compilation will take a while. So I would kindly like to ask you to make the question more precise so that no one puts some major amount of time into this just to hear "Oh, this is not what I wanted".

  • This is exactly, what I was looking for, thank you so much! In my case, it is even enough to use the scopes with canvases on certain planes, because I wanted to visualize a box made up from its unfolded state which is saved in a PDF. – TobiBS Jun 06 '20 at 00:05