
Chapter
14
Distance Methods
I
n all but the last section of this chapter, I present a few algorithms for computing
distances between points, linear components (lines, rays, segments), triangles,
rectangles, and boxes. Linear components are parameterized by P + tD,whereD
is a unit-length vector. The parameter is constrained to t ∈ (−∞, ∞) for a line, to
t ∈ [0, ∞) foraray,andtot ∈ [−e, e] for a segment. The algorithms are set up to
compute squared distance to avoid a potentially expensive square root function call,
but if the cost is not of concern to you, your implementation can very well compute
distance itself.
To encapsulate the heart of the algorithms, ...