Graphics Reference
In-Depth Information
// Repeat test for face adb
if (PointOutsideOfPlane(p, a, d, b)) {
Point q = ClosestPtPointTriangle(p, a, d, b);
float sqDist = Dot(q - p,q-p);
if (sqDist < bestSqDist) bestSqDist = sqDist, closestPt = q;
}
// Repeat test for face bdc
if (PointOutsideOfPlane(p, b, d, c)) {
Point q = ClosestPtPointTriangle(p, b, d, c);
float sqDist = Dot(q - p,q-p);
if (sqDist < bestSqDist) bestSqDist = sqDist, closestPt = q;
}
return closestPt;
}
Here the value of PointOutsideOfPlane(P, A, B, C) corresponds to the sign of
the scalar triple product of the vectors P
A , B
A , and C
A .
// Test if point p lies outside plane through abc
int PointOutsideOfPlane(Point p, Point a, Point b, Point c)
{
return Dot(p - a, Cross(b - a, c - a)) >= 0.0f;
// [AP AB AC] >= 0
}
Often the winding of the tetrahedron vertices is not known beforehand, meaning
it cannot be assumed, say, that face ABC is counterclockwise when viewed from
outside the tetrahedron. In this case, the solution is to additionally pass the fourth
tetrahedron vertex to PointOutsideOfPlane() and make sure it and the tested point
lie on opposite sides of the tested tetrahedron face. In other words, the function then
becomes:
// Test if point p and d lie on opposite sides of plane through abc
int PointOutsideOfPlane(Point p, Point a, Point b, Point c, Point d)
{
float signp = Dot(p - a, Cross(b - a, c - a)); // [AP AB AC]
float signd = Dot(d - a, Cross(b - a, c - a)); // [AD AB AC]
// Points on opposite sides if expression signs are opposite
return signp * signd < 0.0f;
}
 
Search WWH ::




Custom Search