In many problems, we need 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 defining the polyline, so comparing the point with each individual segment must be very fast.
This section defines a segment as the portion of a line bounded by the points and
.
The point
and the segment can have one of three relationships: the nearest point is
, the nearest point is
, or the nearest point lies between the two endpoints.
From a purely computational perspective, calculating these three distances would require nine multiplications, six additions, one division, and three comparisons.
This section shows how the dot product can be used to make the comparison more computationally efficient.
Without loss of generality, assume that
. From the definition of the dot product
| (1.70) |
| (1.71) |
Paolo medici