# 3D Triangulation: Finding the 2d verts?

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

## Recommended Posts

Well I have an idea on how to build my triangles from polygons that are given by verts clockwise defining one point to the next. My problem begins with how do I convert the 3d verts down to 2d to use ear clipping (or any method for that matter)? Here is what I read, or believe I read correctly and I guess im looking for a, "yea u got it buddy" or "a nope yer all wrong, here is what u need to do." : I start by making 2 verts like so(psuedo):
     VertA = vert(1) - vert(0);  // 1 being 2nd vert of poly
VertB = vert(last) - vert(0);  //last being last defined vertex of poly


then I calculate the cross product(norm) of A and B like so:
	const Vector3 Cross ( const Vector3 &arg_ ) const
{
Vector3 temp;

temp.x = y * arg_.z - z * arg_.y;
temp.y = z * arg_.x - x * arg_.z;
temp.z = x * arg_.y - y * arg_.x;

return temp;
}


Then I turn .x, .y, .z into absolute values and proceed to run through a check to find the largest value of .x, .y, .z and remove iton the 2d vert like so:
		for(i = 0; i < uiVerts; i++)
{
if(Normal.x > Normal.y && Normal.x > Normal.z)
{
// drop the x coordinate
GetAtVertex(i)->p.x =	pPoly->GetAtVertex(i)->p.z;
GetAtVertex(i)->p.y = pPoly->GetAtVertex(i)->p.y;
}
else if(Normal.y > Normal.x && Normal.y > Normal.z)
{
// drop the y coordinate
GetAtVertex(i)->p.x = pPoly->GetAtVertex(i)->p.x;
GetAtVertex(i)->p.y = pPoly->GetAtVertex(i)->p.z;
}
else
{
// drop the z coordinate
GetAtVertex(i)->p.x = pPoly->GetAtVertex(i)->p.x;
GetAtVertex(i)->p.y = pPoly->GetAtVertex(i)->p.y;
}
}


Does this seem right to get all my 2d verts for a poly to run a Ear clip on? Seems like its too easy or I missed a large step, just doesnt seem right.... Also why would I want to take a vert and minus another vert from it to get start and end vectors before finding the norm? I understand for the most part but does that define a line or plane for me to grab an actual norm? Thanks in advance! --Brad

##### Share on other sites
Looks good, as long as the polygon is at least close to planar.

One thing-make sure your VertA and VertB are not parallel. This could happen pretty easily:

*2
/ / / *--*----*
3 0 1

cross(vert[1]-vert[0], vert[last]-vert[0]) would be (0,0,0), and when you tryed to normalise that, your computer may explode. But aside from that, it should work fine.

##### Share on other sites
(AP was me)

Ok, so the forum doesn't seem to like backslashes.

    *2    / \   /   \  /     \ *---*---* 3   0    1

That's better.

##### Share on other sites
Ahh i thought for some reason that would pass... But instead when I do my csg they are removed... Now when u say close to planar... are there some instances where this would not work? if so, is there a quick example?

##### Share on other sites
Planar means all the points in the polygon lie on the same plane. Close to planar would just mean they are all close to the same plane. A triangle is always planar, but a polygon with more than 3 points may not be. It is imposible to tesselate a non-planar polygon perfectly, because there is no way of knowing where the surface between the points should lie. Sometimes it will be tesselated the way you want, sometimes it won't. The only time it would cause you serious problems is if the polygon were so twisted that parts of the 2d projection overlap.

##### Share on other sites
Ahh ok very nice, none of them are that twisted, I was converting points from polygons taken from brushes out of the worldcraft (.MAP) format. This is after a CSG so they should not be a problem at all... I was just confused on how it worked in the end there when I took the points into 2d. Im so used to 3d only :). Thanks again, very very helpful.

• 13
• 18
• 29
• 11