Graphics Reference
In-Depth Information
A
n
Q
B
Figure 5.20 Intersecting the segment AB against a plane.
This can now be implemented as follows.
int IntersectSegmentPlane(Point a, Point b, Plane p, float &t, Point &q)
{
// Compute the t value for the directed line ab intersecting the plane
Vector ab=b-a;
t = (p.d - Dot(p.n, a)) / Dot(p.n, ab);
// If t in [0..1] compute and return intersection point
if (t >= 0.0f && t <= 1.0f) {
q=a+t*ab;
return 1;
}
// Else no intersection
return 0;
}
Note that this code does not explicitly handle division by zero. Assuming IEEE-
754 floating-point arithmetic, it does still give the correct result in the case of the
denominator being zero. Refer to Section 11.2.2 on infinity arithmetic for details of
how to correctly deal with division-by-zero errors without having to explicitly test for
them.
If the plane is not explicitly given, but only implicitly specified by three (non-
collinear) points on the plane, the test can be written in the following manner
instead.
 
Search WWH ::




Custom Search