Sign in to follow this  
taurean

3D polygon to 2D polygon

Recommended Posts

taurean    122
hi all, how do i convert a 3d polygon with vertices having x,y & z to a 2d polygon. I need to do this so that I could apply 2d triangulation algorithms on that to tesselate the polygons into triangles. forgot the math behind it. so, help me out. ~ Matt

Share this post


Link to post
Share on other sites
osto    122
did you tried googling 3d to 2d

anyway I have a book i think the name has vb graphic programming. It tell how 3d was done "back in the day" before library came alone. if you need more help just tell. :P

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
You can just drop one of the coordinates. The polygon might get stretched a bit (by example, if you drop the z coordinate of a polygon with the normal close to the y direction), but as long as it isn't too much, your triangulation will work fine. To make sure that you are dropping the coordinate that will result in the lessest stretching, you make it depend on the normal:


first calculate the normal of the polygon:
normal = CrossProduct(vertex1 - vertex0,[lastvertex] - vertex0);

then get the absolute values of the normal coordinates
normal.x = abs(normal.x);
normal.y = abs(normal.y);
normal.z = abs(normal.z);

now decide which coordinate you want to drop, depending on the largest direction of the normal:

if(normal.x > normal.y && normal.x > normal.z)
{
// drop the x coordinate
vert2d.x = vert3d.z
vert2d.y = vert3d.y
}
else if(normal.y > normal.x && normal.y > normal.z)
{
// drop the y coordinate
vert2d.x = vert3d.x;
vert2d.y = vert3d.z;
}
else
{
// drop the z coordinate
vert2d.x = vert3d.x;
vert2d.y = vert3d.y;
}


btw. this is cubic mapping, which I suggested in your other thread.

Share this post


Link to post
Share on other sites
taurean    122
kewl, thatz an awesome reply!!! I made a google search on cubic mapping but nothing found fruitful....thanks though!!...

any idea of simple polygon tesselation algorithm for concave/polygons with holes since time is not a constraint for my implementation.

~ Matt

Share this post


Link to post
Share on other sites
taurean    122
A polygon that is of shape 'C'

|-----|
| |---|
| |
| |
| |
\ \ \___
\____|

hope this ASCII representation helps although it sucks !!

~ Matt

Share this post


Link to post
Share on other sites
taurean    122
" normal = CrossProduct(vertex1 - vertex0,[lastvertex] - vertex0); "


Is that the normal of a polygon is defined by the cross product of vectors formed by itz 1st segment (2nd vertex - 1st vertex) & last segment (last vertex - first vertex), assuming in whatever way the polygon is defined.

assuming a polygon has 5 vertices, ABCDE; it can be defined by any manner, right? BCDEA or CDEAB.

clarify !!

~ Matt

Share this post


Link to post
Share on other sites
quasar3d    814
well, yes, you can take any two edges, as long as they form a convex corner:


a convex corner
/.......
/........
..........
\........
\.......



not a convex corner
\.......
\......
\........
/.........
/.........
/.......


If you use a non convex corner for it, the normal will point to the opposite direction. It will still be perpendicular to the polygon though, so for cubic mapping it's not a problem, and so you can use (almsot) any corner for it. The only vertex that doesn't work is one that has two edges on it that are parallel (and so it in fact isn't a corner). The CrossProduct for those edges will result in a zero length vector. The best way to deal with them will probably be to just try the next vertex if the length of the normal is 0 (or close to 0, taking into account floating point inaccuracy).

I always use the first corner, because in lightwave, the modeler I use, that first corner is guaranteed to be convex.

For triangulating a polygon, I use this way, and it works very well: http://www.magic-software.com/Documentation/TriangulationByEarClipping.pdf

Share this post


Link to post
Share on other sites
taurean    122
I assume the method u recommended (ear..) doesn't handle holes or concave polygons.

I was looking onto seidel's algorithm, do u've any comments about it. It takes polygons with line segments (x,y) form only. Thought of using the above discussed cubic mapping method to clip the one of the vertices in the polygon.

any interesting note on this is appreciated !!

~ Matt

Share this post


Link to post
Share on other sites
quasar3d    814
Quote:
Original post by taurean
I assume the method u recommended (ear..) doesn't handle holes or concave polygons.


Yes, it does

Share this post


Link to post
Share on other sites
taurean    122
thatz great!!....Is there any link that has the algorithm implemented.. I am looking for one implementation to start my own. I found a paper on the algorithm but would like to have a code so that I could test with my set of inputs b4 starting out my own implementation of the same.

appreciate ur reply !!

~ matt

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