
6.6 Linear Components 221
[t
0
, t
1
] (see the subsection in Section A.5 on Sturm sequences for polynomials). If
there are no roots, then P(t) is monotonic on the interval, and the minimum and
maximum distances occur at t
0
and t
1
. If the subinterval is an interior one, then the
minimum distance is not attained on the subinterval. If t
0
or t
1
are end points of
the original parameter interval, then the squared distances at those points must be
compared to any interior local minima that are calculated. If P
(t) hasonerooton
the subinterval, then a robust method such as bisection can be applied to locate the
root. If P
(t) has multiple roots on the subinterval, further subdivision should be
applied to obtain only intervals that have at most one root.
6.6 Linear Components
This section covers the distance algorithms for the six combinations of lines, rays, or
line segments: line-line, line-ray, line-segment, ray-ray, ray-segment, and segment-
segment.
6.6.1 Line to Line
Let the lines be represented by normal forms n
i
· X = c
i
for i = 0, 1. If the two
lines intersect, the distance is zero. Otherwise the lines are parallel, and the distance
between the lines is positive if the lines are disjoint or zero if the lines are the same.
Figure 6.16 illustrates the possibilities. In the case of parallel lines, the distance is
attained at a point P
0
on the first line and a point P
1
= P
0
+ t n
0
on the second
line. The distance itself is t n
0
.Thevalueoft is determined by c
1
=n
1
· P
1
=
n
1
· P
0
+ t n
1
·n
0
, in which case t = (c
1
−n
1
· P
0
)/(n
1
·n
0
). A point on the first line
is P
0
= c
0
n
0
/n
0
2
. Replacing this in the equation for t, substituting that into t n
0
,
and rearranging some terms leads to the distance formula
Distance
L
0
, L
1
=
0, n
0
·n
⊥
1
= 0
|(n
0
·n
0
)c
1
−(n
0
·n
1
)c
0
|
n
0
|n
0
·n
1
|
, n
0
·n
⊥
1
= 0
(6.9)
If n
0
=n
1
, the second portion of the distance formula reduces to |c
1
− σc
0
|/
n
0
,whereσ = Sign(n
0
·n
1
). The division is avoided if additionally n
0
=1.
The equivalent formula for the parametric representations P
i
+ t
i
d
i
, i =0, 1, is
Distance
L
0
, L
1
=
0,
d
0
·
d
⊥
1
= 0
|
d
⊥
0
·
|
d
0
,
d
0
·
d
⊥
1
= 0
(6.10)
where
=P
1
−P
0
. The second portion of the formula is the length of the projection
of
onto a normal line that is perpendicular to the two given lines.