Graphics Reference
In-Depth Information
which when substituted for t in S ( t ) gives the intersection point Q as
A ) ( n
Q
=
A
+[
( d
n
·
·
( B
A ))
]
( B
A ).
If the segment is parallel to the plane, the division denominator will be zero. Under
IEEE-754 arithmetic, for a nonzero x , x /0 gives INF or
INF (depending on the sign
of x ). If x is zero, the result is NaN instead. In all of these cases, the code should
correctly return nonintersection as the result. This can be accomplished by making
sure the test for t being in the range
[
0, 1
]
is performed correctly, as illustrated by the
following code.
// Test if segment AB intersects plane p. If so, return 1, along with
// the intersection t value and the intersection point Q. If not, return 0
int IntersectSegmentPlane(Point a, Point b, Plane p, float &t, Point &q)
{
// Compute t value at which the directed line ab intersects 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 t is +INF, -INF, NaN, or not in [0..1], so no intersection
return 0;
}
Under the IEEE-754 standard, INF and NaN exceptions are further supported by
the concept of “sticky” exception flag bits. These global flags are set whenever an
exception occurs, and remain set until cleared. They allow for implementing robust
code by first performing a quick-and-dirty solution that does not test for overflows,
division-by-zero errors, and so on. If after the computation no sticky bits are set, the
result can be used as is. However, if one or more exceptions occurred with corre-
sponding sticky bits set then a slower but more robust version of the code is called.
Not all compilers and not all machines are fully compliant with respect to the IEEE
rules of infinity arithmetic, and thus it is important to verify the correct behavior
before relying on these features in an implementation.
11.2.3 Floating-point Error Sources
Although well defined, floating-point representations and arithmetic are inherently
inexact. A first source of error is that certain numbers are not exactly representable in
 
Search WWH ::




Custom Search