int GetDropCoord(Vector3D v)
// Get the coordinate which could be dropped:
{
double x,y,z;
x=fabs(v.x());
y=fabs(v.y());
z=fabs(v.z());
if (x>=y)
if (x>=z)
return DROPX;
if (y>=x)
if (y>=z)
return DROPY;
return DROPZ;
}
Point2D DropCoord(Point3D p,int drop)
// Drop the drop-coordinate from the 3D point and returns the resulting 2D point.
{
switch(drop)
{
case DROPX:
return Point2D(p.y(),p.z());
case DROPY:
return Point2D(p.x(),p.z());
case DROPZ:
return Point2D(p.x(),p.y());
default:
return Point2D(p.x(),p.y());
}
}
int InsideLoop(Loop *l,Vertex *v)
// l = loop of a face. v = intersection point
// of ray with loop.
{
int drop=GetDropCoord(l->face); // Get drop coord from the face normal.
Point2D x = DropCoord(v->pnt,drop); // Drop a component to project the intersection.
int n = NumberOfPointsInLoop(l);
// Now convert all 3D points in this loop to 2D points by projection:
Point2D *pnt = new Point2D[n];
HalfEdge *scan=l->hEdge;
n=0;
do
{
pnt[n] = DropCoord(scan->vertex->pnt, drop);
n++;
}
while ((scan=scan->next)!=l->hEdge);
return Math2DInsidePolygon(pnt,n,x); // Test, if x lies inside loop.
}