In several problems, it is necessary to determine the distance between a point and a polyline consisting of multiple segments.
The computational cost of this problem grows linearly with the number of points making up the line; therefore, to perform these analyses, comparison with an individual point must be very fast.
In this section, a segment is defined as the portion of a line bounded by the points and
.
The point
and the segment can be related in three ways: the closest point is
, the closest point is
, or the closest point lies between the two endpoints.
From a purely computational standpoint, calculating these three distances would require nine multiplications, six additions, and one division, in addition to the necessary three comparisons.
This section shows how the comparison can be improved computationally using the dot product.
Without loss of generality, we can assume that
. From the definition of the dot product
| (1.70) |
| (1.71) |