Sign in to follow this  
Donner

Projecting Polygons to 2D plane and back to 3D

Recommended Posts

Hey, I want to clip two faces (polygons) of two Boxes (not axis aligned) with eatch other. The two polygons have the same normal, so they are parallel and they are on the same plane (the distance between them is 0). Since I know how to clip 2D-Polygons, I want to have 2D-Coordinates instead of 3D (since they share the same normal and are on one plane already, I want to use that plane as the "2D-World"...). After clipping, I want to convert them back to 3D-Coordinates. Does anybody know how to do that? Thanks a lot, D.

Share this post


Link to post
Share on other sites
If you take any two unique points on the plane (from the polygons for instance), you can create a vector on the plane -- call it 'U'. Given normal 'N', you can do NxV and get a third vector 'V'. Once you normalize 'U' and 'V' (assuming 'N' is already normalized), you then have all you need to generate a transformation matrix that will give you 2D coordinates. Take a 3x3 matrix 'M' and plug 'U', 'V', and 'N', into each of the three rows, respectively. Transform all points 'P' from all polygons using M·P. From there on out you can perform the 2D clipping by simply ignoring the Z-component of the transformed points. When you're done, you transform all points back using MT·P. They should all have the same Z-value they had after you performed the first transformation because you've been ignoring it.

Share this post


Link to post
Share on other sites
Hey,

thank you for the fast answer! :)

Quote:
Original post by ZipsterThey should all have the same Z-value they had after you performed the first transformation because you've been ignoring it.


But during the clipping process there will be new points created. How do I find their Z-Values? Or am I getting something wrong?

Share this post


Link to post
Share on other sites
Quote:
Original post by Donner
Quote:
Original post by ZipsterThey should all have the same Z-value they had after you performed the first transformation because you've been ignoring it.


But during the clipping process there will be new points created. How do I find their Z-Values? Or am I getting something wrong?

All the transformed points from the original polygons will have the same Z-value because they're on the same plane, so for all new points just plug in that Z-value to put them on the plane.

Share this post


Link to post
Share on other sites
And it doesn't matter what I chose the Vector 'U' to be as long as it is on the plane? (So the Vector from Point A to Point B, if both points are on the plane, right?)

And one more question about the matrix: Will it be one Row for eacht Vector (saying U goes in the first, V in the second and N in the third row?) Or is it that the X-Xomponents of the three vectors go in the 1st row, the Y-Components in the second etc.?

Thank you so much!

Share this post


Link to post
Share on other sites
Quote:
Original post by Donner
And it doesn't matter what I chose the Vector 'U' to be as long as it is on the plane? (So the Vector from Point A to Point B, if both points are on the plane, right?)

That's correct, it can be anything on the plane.

Quote:
And one more question about the matrix: Will it be one Row for eacht Vector (saying U goes in the first, V in the second and N in the third row?) Or is it that the X-Xomponents of the three vectors go in the 1st row, the Y-Components in the second etc.?

One row for each vector, so:

| U.x U.y U.z |
| V.x V.y V.z |
| N.x N.y N.z |

Share this post


Link to post
Share on other sites

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