# Projection of included 2D graphics to a plane

## General purpose

I want to project a graphic file from external sources (example.pdf saved on my computer e.g. a chip design) on the bottom of a 3D graphic (which I can draw in LaTeX by using TikZ, pstrick or asymptote).

I know that it works for text letters, see How to project text onto a plane?. So I guess that it would also work with an included graphics!

## Example using TikZ

I also achieved a minor step towards this goal but I am not happy with performing a 2D rotation in 3D. How can I configure the command

/tikz/cm={a, b, c, d, coordinate}


in order to perform a 3D rotation? The command is given in the tikz-pgf manual (v3.0.0, p.363) in chapter 25.3. Or is there a simpler way to go? Also Canvas Transformation could be used...

By the way, I perform 3D rotations by using

\tdplotsetmaincoords{phi}{theta}


which is contained in the package tikz-3dplot.

My MWE:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{3D,calc}

\begin{document}

\begin{tikzpicture}
\coordinate (chip) at (0,0,0);
\node[cm={1,0,cos(20),sin(20),(0,0)}] at (coordA){\includegraphics[width=20em]{example.pdf}};
\end{tikzpicture}
\end{document}


## Asymptote

I am also interested whether I can include graphics with asymptote or not.

## EDIT (not minimal tikz example):

I want to give you an impression what I am intended to do:

\documentclass[border=5pt]{standalone}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{calc}

\newcommand{\drawrect}[4]{
\fill[red!50,opacity=0.5] #1 -- #2 -- #3 -- #4 -- cycle;
}

\begin{document}

\begin{tikzpicture}
% Underlaying graphics:
\node[cm={cos(-20),sin(-20),sin(80),cos(80),(0,0)}]{\includegraphics[width=20em]{example-image.pdf}};
% Position of the box:
\tdplotsetmaincoords{75.3}{55}
\begin{scope}[tdplot_main_coords,scale=1]
\coordinate (positionA) at (+2.2,0,0);
\end{scope}
% Draw the rotated box:
\tdplotsetmaincoords{75.3}{55+90+9};
\begin{scope}[tdplot_main_coords,scale=1]
% Rectangle's (side's) half sizes
\coordinate (RectangleX) at (1.15,0,0);
\coordinate (RectangleY) at (0,1.15,0);
\coordinate (RectangleZ) at (0,0,0.2);
% Center of cube:
\coordinate (root) at ($(positionA)+(RectangleZ)$);
% Cube:
\drawrect
{($(root)-(RectangleX)-(RectangleY)-(RectangleZ)$)}
{($(root)+(RectangleX)-(RectangleY)-(RectangleZ)$)}
{($(root)+(RectangleX)-(RectangleY)+(RectangleZ)$)}
{($(root)-(RectangleX)-(RectangleY)+(RectangleZ)$)}
\drawrect
{($(root)-(RectangleX)-(RectangleY)-(RectangleZ)$)}
{($(root)+(RectangleX)-(RectangleY)-(RectangleZ)$)}
{($(root)+(RectangleX)+(RectangleY)-(RectangleZ)$)}
{($(root)-(RectangleX)+(RectangleY)-(RectangleZ)$)}
\drawrect
{($(root)-(RectangleX)-(RectangleY)-(RectangleZ)$)}
{($(root)-(RectangleX)-(RectangleY)+(RectangleZ)$)}
{($(root)-(RectangleX)+(RectangleY)+(RectangleZ)$)}
{($(root)-(RectangleX)+(RectangleY)-(RectangleZ)$)}
\drawrect
{($(root)+(RectangleX)+(RectangleY)+(RectangleZ)$)}
{($(root)+(RectangleX)+(RectangleY)-(RectangleZ)$)}
{($(root)+(RectangleX)-(RectangleY)-(RectangleZ)$)}
{($(root)+(RectangleX)-(RectangleY)+(RectangleZ)$)}
\drawrect
{($(root)+(RectangleX)+(RectangleY)+(RectangleZ)$)}
{($(root)+(RectangleX)+(RectangleY)-(RectangleZ)$)}
{($(root)-(RectangleX)+(RectangleY)-(RectangleZ)$)}
{($(root)-(RectangleX)+(RectangleY)+(RectangleZ)$)}
\drawrect
{($(root)+(RectangleX)+(RectangleY)+(RectangleZ)$)}
{($(root)-(RectangleX)+(RectangleY)+(RectangleZ)$)}
{($(root)-(RectangleX)-(RectangleY)+(RectangleZ)$)}
{($(root)+(RectangleX)-(RectangleY)+(RectangleZ)$)}
\end{scope}
\end{tikzpicture}
\end{document}


which results in:

## Other application

It is somehow similar to an architect's plan. A 2D plan below and a simple 3D structure on top of it.

• For someone who is already used to LaTeX, the simplest way to include graphics in Asymptote is to create a label with the text (in your case) "\includegraphics[width=20em]{example.pdf}". Two notes here. First, if your included graphic is anything other than an eps file, then you need to make sure the line settings.tex="pdflatex"; shows up near the beginning of your asymptote code. Second, this will only work if your label is positioned using 2d coordinates; if you try to position it directly in the 3d picture, it will show up as a great big black rectangle. Commented Jan 18, 2014 at 22:10
• Could you provide an example of this? Commented Mar 18, 2014 at 16:59

In a cube the bottom is invisible, the reason why I define an own plane P2inner. Needs the lates pst-solides3d and an eps image which has only basic line elements, like lineto curveto and moveto:

\documentclass[pstricks]{standalone}
\usepackage{pst-solides3d}
\begin{document}

\psset{viewpoint=20 -120 30 rtp2xyz,Decran=20,unitPicture=15,lightsrc=viewpoint}
\begin{pspicture}[solidmemory](-7,-9)(8,3)
\psSolid[object=plan,definition=normalpoint,base=-6 6 -6 6,args={0 0 -4 [0 0.1 1]},
fillstyle=solid,linecolor=black!15,fillcolor=black!10,name=P2inner]
\psImage[unitPicture=30,file=tiger.eps,origine=0 0 -4,normal=0 0 1,phi=180](-4,0)
\psSolid[object=cube,a=4,name=Cube,linecolor=red,numfaces=all,fontsize=100,
RotZ=20,action=draw]
\psImage[unitPicture=30,file=tiger.eps,origine=Cube 0 solidcentreface,normal=Cube 0 solidnormaleface,phi=-90]
\psImage[unitPicture=30,file=tiger.eps,origine=Cube 3 solidcentreface,normal=Cube 3 solidnormaleface]
\psImage[unitPicture=30,file=tiger.eps,origine=Cube 2 solidcentreface,normal=Cube 2 solidnormaleface]
\end{pspicture}

\end{document}


• Thank you for this nice answer! But I was looking for an answer where the base plane is larger than the 3d solid cube (which should be rotatable) on top of it. See my figure provided in my question. Commented Mar 21, 2014 at 9:31
– user2478
Commented Mar 21, 2014 at 10:03
• It is better. Is it possible to position the cube with another orientation (just rotate on plane)? Like \psSolid[object=cube,phi=45,a=8,action=draw,linecolor=red,name=A]. I also want to include a figure in the plane. Commented Mar 21, 2014 at 10:32
• use RotZ=-45. Images must be of type eps but I must see how it works. Forgot it ... :-(
– user2478
Commented Mar 21, 2014 at 11:01
– user2478
Commented Mar 23, 2014 at 7:25

Not sure if this is what you want, but adapting the code provided by Alain Matthes in How to project text onto a plane? is easy to obtain

The code is:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usepackage{mwe}
\usetikzlibrary{3D,calc}

\begin{document}

\begin{tikzpicture}[x={(0.5cm,0.5cm)}, y={(1cm,0cm)}, z={(0cm,1cm)}]
\begin{scope}[canvas is yx plane at z=0]
\node[draw,transform shape] (a) {\includegraphics[width=20em]{example-image.pdf}};
\end{scope}

\foreach \i in {south west, south east, north east, north west}
\draw[dashed] (a.\i) --++(0,0,2) coordinate(b-\i);

\draw (b-south west)--(b-south east)--(b-north east)--(b-north west)--cycle;

\end{tikzpicture}
\end{document}

• In principle you're completely right. My goal is to draw only smaller boxes on part of the image, e.g. drawing some items (fan etc.) on top of a motherboard. I thought also of rotating the image. In addition the boxes on top of it have some orientation which is refusing the additional rotation of the image. Commented Jan 20, 2014 at 8:01
• @strpeter I'm sorry but I don't understand what's your problem. Could you show us an image with your wrong results? What's this "additional rotation"? Commented Jan 20, 2014 at 18:03