3D polygon to 2D polygon

Started by
10 comments, last by taurean 19 years, 9 months ago
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
Advertisement
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
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 coordinatesnormal.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 coordinatevert2d.x = vert3d.zvert2d.y = vert3d.y}else if(normal.y > normal.x && normal.y > normal.z){// drop the y coordinatevert2d.x = vert3d.x;vert2d.y = vert3d.z;}else{// drop the z coordinatevert2d.x = vert3d.x;vert2d.y = vert3d.y;}


btw. this is cubic mapping, which I suggested in your other thread.
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
what exactly do you mean with holes?
A polygon that is of shape 'C'

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

hope this ASCII representation helps although it sucks !!

~ Matt
" 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
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
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
Quote:Original post by taurean
I assume the method u recommended (ear..) doesn't handle holes or concave polygons.


Yes, it does

This topic is closed to new replies.

Advertisement