Sign in to follow this  

Back project square from 2D to 3D

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Dear experts, I am working on a project where i need to do back-projection of points on screen to their 3D wolrd positions and i need your help in this regards. I have 4 fixed points that represent a square in 3D world parallel to the X-Z plane. After applying transformation effects (rotation and translation) these points get projected to arbitrary points on screen (2D). I need to project back these points from screen coordinates to their actual 3D points keeping in mind preserving the square shape they represent. For example: 3D World 2D Screen the square *-------* *---* | | could be projected to / \ | | (perpective) / | | *---------* *-------* or roughly to * (perspective and / rotation) / \ * * \ / \ / * can any one help please? cheers AF

Share this post


Link to post
Share on other sites
use [ code ] and [ /code ] tags around your ASCII art to preserve formatting (though it might not be exactly what it is when you edit it. Eg: it uses a different font.

Share this post


Link to post
Share on other sites
Hi again,

this is the example i wanted to give in my post witht he proper formating (thanx Ezbez)



For example:
the square in 3D:
o-------o
| |
| |
| |
o-------o

could be projected to in 2D(perpectivei applied):

o------o
/ /
/ /
/ /
o-----------o


or roughly to (perspective and rotation)

o
/ \
/ \
o o
\ /
\ /
o


[Edited by - abolfoooud on May 10, 2007 6:38:08 AM]

Share this post


Link to post
Share on other sites
If what you need are the coordinates of the untransformed vertexes, then what you need to do is transform the screen-space coordinates using the inverse of the original transformation, which is:
Vs = M . Vw

where Vs is in screen space and Vw is in world space and M is a matrix representing the transformation from world to screen space (most likely a concatenation of a projection matrix and a view matrix).

Given Vs = ( xs, ys, zs ) (the 2D coordinates of each vertex on the screen and a screen space depth), compute the inverse of M, M-1 to get Vw:
Vw = M-1 . Vs


If you do not have a screen space depth, you can substitute for 0 and 1. What you then get is a line of sight starting from the camera (given M has a view matrix) to infinity, passing through Vw at some time t.

Share this post


Link to post
Share on other sites
It's good practice to know the general way to solve these problems, even though you could take short cuts in this particular case. Given all the information you know about the starting data, you can use different means to find your answer. The general solution to this problem though is to find the inverse matrix, which is done [for square matrices] by dividing every term in the matrix by the non-zero determinant. If the determinant is zero, then there is no inverse. You won't run into a zero-determinant in these cases, unless you're doing something amazingly wierd with your original transform matrix.

By the way, thats a great site for just these kinds of problems. It's definately bookmark-worthy.

Share this post


Link to post
Share on other sites
the site gives example of how apply the inverse of 3x3 matrix. but in the case of OGL we need 4x4. calculating this for 4x4 will be i am sure tooo ime costy and will affect performance. i read somewhere that there are shortcuts or work-arounds to get the inverse.

also the site has theoratical explanation. is there a technical one showing opengl code to use? i know i am too lazy :D

cheers

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this