Graphics Reference
In-Depth Information
d removes
the need for an often expensive division this may have undesirable effects on the
overall robustness of the solution (due to the size of the intermediary terms). Ideally,
the cylinder direction is given as a unit vector d , in which case all d
Note that although multiplying the original quadratic equation by d
·
d terms dis-
appear. (In fact, if d is unit the cylinder surface can be more succinctly defined as
( v
·
r 2 .)
In either case, both equations are quadratic equations in t on the form at 2
×
d )
·
( v
×
d )
=
+
2 bt
+
c
=
0. For the latter formulation, the terms are:
d ) 2
a
=
( d
·
d )( n
·
n )
( n
·
b
=
( d
·
d )( m
·
n )
( n
·
d )( m
·
d )
r 2 )
d ) 2 .
c
=
( d
·
d )(( m
·
m )
( m
·
These terms can be rewritten using Lagrange's identity as
a
=
( d
×
n )
·
( d
×
n )
b
=
( d
×
m )
·
( d
×
n )
r 2 ( d
c
=
( d
×
m )
·
( d
×
m )
·
d ),
thus revealing that a
0 indicates that d and n are parallel and that a is always
positive (although small errors may make it negative when working with floating-
point arithmetic). The sign of c indicates whether A lies inside ( c
=
<
0) or outside
>
( c
0) the surface of the cylinder. Solving for t gives
b 2
=
±
b
ac
t
.
a
The sign of the discriminant b 2
ac determines how many real roots the quadratic
has. If negative, there are no real roots, which corresponds to the line not intersecting
the cylinder. If positive, there are two real roots, the smaller of which being the
parameterized value at which the line enters and the larger when it exits the cylinder.
When the discriminant is zero, there is a single root signifying that the line is touching
the cylinder tangentially in a single point at parameterized value t .
To detect intersection against a finite cylinder rather than an infinite cylinder, inter-
sections beyond the endcap planes through P and Q and perpendicular to d must
not be treated as intersections with the cylinder. Unless the (directed) line query
points away from the endcap plane, an intersection test against the plane must be
performed to detect a potential intersection with the side of the finite cylinder. Given
a valid t , L ( t ) lies outside the plane through P if ( L ( t )
·
<
P )
d
0, or equivalently
 
Search WWH ::




Custom Search