In various problems, it is necessary to know the distance between a point and a polyline formed by multiple segments. The computational weight of this problem grows linearly with the number of points that make up the line: in order to perform these analyses, it is essential that the comparison with the single point is therefore very fast.
In this section, a segment will be defined as that part of the line bounded by the points and
. The point
and the segment can relate in 3 ways: the closest point is
, the closest point is
, or the closest point is a point between the two endpoints.
From a strictly computational point of view, calculating these 3 distances would require 9 multiplications, 6 additions, and one division, in addition to the necessary 3 comparisons. This section shows how the comparison can be computationally improved by using the dot product.
Without loss of generality, one can assume that
. From the definition of the dot product
| (1.34) |
| (1.35) |
Paolo medici