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).

  • $\begingroup$ Please describe the rotated surface that the mouse click is projected onto. Is it a plane? A sphere? A Mickey Mouse head? $\endgroup$
    – vadim123
    Feb 12 '14 at 14:35
  • $\begingroup$ @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). $\endgroup$ Feb 12 '14 at 14:39
  • $\begingroup$ Please have a look here : en.m.wikipedia.org/wiki/3D_projection $\endgroup$
    – Yiyuan Lee
    Feb 12 '14 at 14:45
  • $\begingroup$ Not enough info to find a unique solution, IMO. $\endgroup$
    – bubba
    Feb 12 '14 at 14:45
  • $\begingroup$ @YiyuanLee, for the record I am for a "mapping" 2d into 3d (while 3d projection is mapping 3d into 2d) $\endgroup$ Feb 12 '14 at 15:00

I assume that by “surface” you actually mean plane.

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.

The “main point” in 3d should however not be the location of the camera, but should instead be a point on the plane. And if your coordinates are coordinates as seen by the camera, then a simple Cartesian coordinate system is not what you need. Instead you'd have to take care of perspective deformations. For that you'd need more information than you provided.

  • $\begingroup$ Absolutely great! Thank you very much for the solution and all the remarks -- they will be very helpful when debugging the code. $\endgroup$ Feb 13 '14 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.