Graphics Reference
In-Depth Information
// Return value specifying whether the polygon 'poly' lies in front of,
// behind of, on, or straddles the plane 'plane'
int ClassifyPolygonToPlane(Polygon *poly, Plane plane)
{
// Loop over all polygon vertices and count how many vertices
// lie in front of and how many lie behind of the thickened plane
int numInFront = 0, numBehind = 0;
int numVerts = poly- > NumVertices();
for(inti=0;i<numVerts; i++) {
Point p = poly->GetVertex(i);
switch (ClassifyPointToPlane(p, plane)) {
case POINT_IN_FRONT_OF_PLANE:
numInFront++;
break;
case POINT_BEHIND_PLANE:
numBehind++;
break;
}
}
// If vertices on both sides of the plane, the polygon is straddling
if (numBehind != 0 && numInFront != 0)
return POLYGON_STRADDLING_PLANE;
// If one or more vertices in front of the plane and no vertices behind
// the plane, the polygon lies in front of the plane
if (numInFront != 0)
return POLYGON_IN_FRONT_OF_PLANE;
// Ditto, the polygon lies behind the plane if no vertices in front of
// the plane, and one or more vertices behind the plane
if (numBehind != 0)
return POLYGON_BEHIND_PLANE;
// All vertices lie on the plane so the polygon is coplanar with the plane
return POLYGON_COPLANAR_WITH_PLANE;
}
Because the introduction of an epsilon only moves the problem of correctly deter-
mining if points lie on the plane to correctly determining if points lie at epsilon
distance from the plane, it may seem like nothing is gained by this procedure.
However, two things are gained. First, polygon edges are guaranteed to have both
endpoints at (roughly) epsilon distance or more from the plane. Having a minimum
distance for the endpoints from the plane increases the angle of the edge to the
plane, in turn increasing the accuracy in computing the intersection point between
the edge and the plane. Second, with an appropriate epsilon the intersection point
can be guaranteed to lie on the thick plane. Although points lying at (near) epsilon
 
Search WWH ::




Custom Search