# 2D to 3D points Projection

This topic is 4136 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I have been struggling with this for a long time. I have had some valuable responses and solutions from guys here in the forum. But i think what i had is a bit too much far for the task am after, i gues so. I want to get the 3D position in the 3D world of a 2D point on screen. I know that i have to go through the backprojection process of the matrices with revesing the transformations applied to the scene. I know that a 3D point is transformed in general as follows: [x', y', z'] = P C W [x,y,z] where P is the projection matrix, C is camera coord transformations, and W is World coords tranformations. Then after this what is projected on the projection plane will be converted to screen coods. THIS IS what i need to get its reverse. I am not interested in the other transformations. Normally, a point p in the 3D world is projected, after the transformations applied to it, to point p' on the projection plane. So as a result, if p = [x, y, z] ---------> (1) then its projection is p' = [x', y', z'] = [ dx/z, dy/z, d] -------------> (2) where d is the distance between the center of projection and the projection plane (i am supposing here that the projection plane is in front of the center of projection). from equations (1) and (2) it should be implied that: x' = dx/z ---------> (3) y' = dy/z ---------> (4) z' = d if i have the coords of p'(screen x and y) and d, can i solve for (3) and (4) to find the x, y, z of the 3D point? Would that be possible? I tried but i could not do it. is there any way of finding these values? These values will represent the point in the 3D world after appling the transformations to it. I dont need to know its original position beofre these transforms. thax in advance AF

##### Share on other sites
If you only have x and y you cannot find a point in 3D space without also knowing the depth (z). Projecting a 2D point to 3D gives you a line. If you're doing 3D picking (user clicks to select an object in 3D space) you can get the depth from your depth buffer as you've probably just rendered the scene for the user to see.

##### Share on other sites
Hi,

Thnax for the reply. Ok, i have another scenario.

What if the point P in the 3D world whose projection on screen is P' is callibrated to another point Q in the 3D world whose projection is Q'? We have Q, Q' and P knowns and need P. Will it be possible to solve this with consider that P = MQ where M is a transformation matrix but unknown (ie P originally was Q before applying any trans on it)?

thanx

##### Share on other sites
There are a few things in your original post that need some clarification. You keep referring to P as the projection matrix, however that's a bit of a misnomer since the matrix doesn't actually perform projection. Perspective would be more appropriate. The reason I make such a fuss over terminology is because once you apply the perspective matrix to get a 4D homogeneous clip-space coordinate [x y z w], you first divide out the w to get [x/w y/w z/w] and then essentially perform an implicit projection to get a 2D screen coordinate by "throwing out" z/w. Projection can be represented by a matrix transformation, however it's an un-invertible matrix in this case. The bottom line is that you need that third coordinate z/w, like what coordz said, to "undo" the projection. There's not enough information otherwise.

Quote:
 Original post by abolfoooudWhat if the point P in the 3D world whose projection on screen is P' is callibrated to another point Q in the 3D world whose projection is Q'? We have Q, Q' and P knowns and need P. Will it be possible to solve this with consider that P = MQ where M is a transformation matrix but unknown (ie P originally was Q before applying any trans on it)?

It won't work mathematically because there are three unknowns and two equations. You still don't have the transformation that takes you from Q' to Q. If you did, then you would just apply it directly to P' (why even bother going from Q' to Q to P). But if you did have such a transformation, it would mean you were able to invert the original one from P to P', which makes the assumption there was no projection and you still had the original z/w. Hence we're back where we started :)

##### Share on other sites
If that is the case, then how do the guys of augmented reality do it??
they use callibration to identify points on screen and the use these to caculate the 3d location of the marker corner points???
I am really lost here :( i am sorry is this question is posted here without relevance but this is what i have been tryin to acheive since ages

AF

[Edited by - abolfoooud on June 15, 2007 9:59:23 AM]

##### Share on other sites
Having read your post, I felt as we had once discussed this a while back and since I was not clear on that, I gave google a try which yielded Backwards Projection

That seemed to be the same problem and you seemed as if you were clear on what had been discussed there. Is there any reason you feel lost again?

Quote:
 If you're doing 3D picking (user clicks to select an object in 3D space) you can get the depth from your depth buffer as you've probably just rendered the scene for the user to see.

I would argue against reading from the depth buffer since any read-backs from video memory residing buffers turns to be awfully slow.

##### Share on other sites
This community is full of great people who are just more than happy to help so don't hesitate to ask. If you have problems grasping an idea or find implementing a method of doing things difficult (and sometimes they are!) don't hesitate to ask. Don't leave a thread without fully understanding the solution or giving the ideas a serious thought.

The Model, view and projection transformations are what most people seem to notice. What is usually ignored or overlooked is 1)the importance of the w component and the homogeneous coordinates and 2)the transformations that take place after these first three. If you are planning to fully understand the process of 3D picking or backwards projection and you intend to implement the process yourself instead of using some ready to use API call (which is sometimes all you need) you have to get your hands dirty and dig deep into the transformation stage of the pipeline to understand its ins and outs. If you are rusty on the basics (not necessarily meaning simple) you will have a hard time understanding the details.

So what we are going to do is work together. Let's make back projections history once and once for all ;) but this time, instead of writing a long post describing the whole process like the other time, we would go step by step. Try reading the previous thread a couple of times and let us know which parts you have problems understanding. The solution to your question is really there. There are even some code from Basiror. Be more specific. Is it the theory or the implementation details that you have problems with?

Peace

##### Share on other sites
Hi Ashkan,

yes indeed i raised this question before but in a slightly different direction (i guess). I am trying here to approach a solution in a way different than what was suggested in the previous thread for several reasons:

1- i wanted to try to solve this using callibration (with another point or set of points) as the Augmented Realty people do.
2- i am using OpenGL ES 1.0 (for mobile devices) which does not have glGetFloat function. This prevents me from retreving the PROJECTION matrix. It has an implementation for OES_query_matrix extension which does retreive the matrix just after it is loaded, ie after glMatrixMode(GL_MODELVIEW); or after glMatrixMode(GL_PROJECTION); In this case i will only be able to retreive the projection matrix inside Init() function, as glMatrixMode(GL_PROJECTION); is usually called there (or in resize()). Not having the projection matrix i guess will not help :(
3- I do not want to do intersection test. I want to return a 2D point on screen to its actual 3D point in the 3D world to calculate a new coordinate system from 3 points (x and z direntioons and the origin) to be able to transfomr models according to it for Augmented Reality use.

this is the hassle i have been in for along time :( i just want to acheive an AR effect. i read many papers but never got to the exact approach. they are using callibration so i thought trying this will help.

so this is my sad storey at the end :p :D

peace

##### Share on other sites
Quote:
 i am using OpenGL ES 1.0 (for mobile devices) which does not have glGetFloat function. This prevents me from retreving the PROJECTION matrix

void MATRIX44::frustum( float l, float r, float b, float t, float n, float f )
{

// 2n r+l
// ---- 0 ----- 0
// r-l r-l

// 2n t+b
// 0 ---- ----- 0
// t-b t-b

// f+n 2fn
// 0 0 - ---- - ----
// f-n f-n

// 0 0 -1 0

a00 = (2.0*n) / (r-l);
a10 = 0.0;
a20 = 0.0;
a30 = 0.0;

a01 = 0.0;
a11 = (2.0*n) / (t-b);
a21 = 0.0;
a31 = 0.0;

a02 = (r+l) / (r-l);
a12 = (t+b) / (t-b);
a22 = -(f+n) / (f-n);
a32 = -1.0;

a03 = 0.0;
a13 = 0.0;
a23 = -(2.0*f*n) / (f-n);
a33 = 0.0;
}

void MATRIX44::perspective( float fovy, float aspect, float n, float f )
{
float xmin, xmax, ymin, ymax;

ymax = n * tanf( fovy * DEG2RAD * 0.5 );
ymin = -ymax;

xmin = ymin * aspect;
xmax = ymax * aspect;

frustum( xmin, xmax, ymin, ymax, n, f);
}

1. 1
2. 2
3. 3
4. 4
Rutin
15
5. 5

• 14
• 9
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
632912
• Total Posts
3009194
• ### Who's Online (See full list)

There are no registered users currently online

×