# How to transform point in 2d into 3d?

This is not a homework, I simply have to write some code and it appears my math skills are a bit rusty ;-).

What I have: main point in 2d of the 2d surface, and main point counterpart in 3d plus the normal vector to the 3d surface. I also have 3d counterpart of (0,1) vector from 2d.

My input is some point in 2d and my objective is to compute its coordinates in 3d. How to do it?

If you wonder what is it -- it is quite simple, I have my screen, as usual, the user clicks on the screen, so I have my (x,y) for the mouse coordinates and I have to take the screen surface and shift+rotate it in 3d to get the center of screen located in the "main" point (camera) in 3d and then find out the coordinates of the mouse click in 3d on this rotated surface.

This would give infinite number of solutions, but I also have given the 3d counterpart of (0,1) vector and the normal vector to the 3d surface (the direction of view) so it should be doable (I mean with 1 outcome).

• Please describe the rotated surface that the mouse click is projected onto. Is it a plane? A sphere? A Mickey Mouse head? Feb 12 '14 at 14:35
• @vadim123, it is still a surface (flat) in such way, that let's say my (0,1) vector is transformed into vector UP (in 3d). UP is given as input (it is known). Feb 12 '14 at 14:39
• Please have a look here : en.m.wikipedia.org/wiki/3D_projection Feb 12 '14 at 14:45
• Not enough info to find a unique solution, IMO. Feb 12 '14 at 14:45
• @YiyuanLee, for the record I am for a "mapping" 2d into 3d (while 3d projection is mapping 3d into 2d) Feb 12 '14 at 15:00

You can compute the cross product between the image of the $(0,1)$ vector and the normal vector of the 3d plane. That will be a vector orthogonal to both, which you can then consider as the image of the $(1,0)$ vector.
You can then interpret each point $(x,y)$ in the plane as $x\cdot(1,0)+y\cdot(0,1)$ and translate this to 3d as $v_0 + x\cdot v_x + y\cdot v_y$. If your “main points” are not the origin of their respective coordinate system, you'd first subtract the 2d “main point”, then do the above conversion to 3d, then add the 3d “main point”. All of this would establish a Cartesian coordinate system on a given plane in 3d.