Chapter
6Distance in 2D
This chapter contains information on computing distance between geometric prim-
itives in 2D. An application might not want to pay the price for an expensive square
root calculation, so many of the algorithms in this chapter provide a construction for
squared distance. Of course, fundamental to any distance algorithm is the squared
distance between two points X =(x
0
, x
1
) and Y = (y
0
, y
1
)
Distance
2
(X, Y)=X − Y
2
= (x
0
− x
1
)
2
+ (y
0
− y
1
)
2
(6.1)
We will discuss algorithms for computing the distance between a point and an-
other object first; other combinations are discussed later in the chapter. When both
objects are convex with polyline or polygonal boundaries, including the degenerate
case when one is a linear component, the distance algorithms can be implemented
by applying a derivativeless numerical minimizer using the point-object formulas.
For example, the distance between a line segment and a triangle can be computed
as a minimization of a one-dimensional function. If F(X, T)is the squared distance
between the point X and the triangle T , then the squared distance between a line
segment X(t) = P
0
+ t(P
1
− P
0
), t ∈ [0, 1], and the triangle is G(t) = F(X(t), T).
A numerical minimizer can be applied to G(t) for t ∈ [0, 1]. Such an iterative ap-
proach certainly can produce a reasonable numerical estimate for the squared dis-
tance, but typically the approach takes more time to find the estimate than a method
that computes the squared distance using a noniterative method. The trade-off is ease
of implementation versus time efficiency of the algorithm.
189