- Calculate the nearest point on the line tangent to each edge of the polygon.
- Calculate the nearest point on each line segment (the edge of the polygon) to the point in question.
- Calculate the distance from the nearest point on each line segment to the point in question.
- . .
- (O (n)).
:
, .
p1 = {x1, y1}.p2 = {x2, y2}.p3 = {x3,y3}.u - p1 p2, , p1 p2, p1+u(p2-p1)= p3 ( p3 , p1 p2).u = ((x3 - x1)(x2 - x1)+(y3 - y1)(y2 - y1)) / ((x2 - x1)^2 + (y2 - y1)^2)- , p3 , p1 p2,
pu = {xu, yu} xu = x1 + u (x2 - x1)yu = y1 + u (y2- y1)- , ,
pu = {xu, yu} - (.. p1s p2s)
( ) .
pu , 0 <= u <= 1. . , pu, p1, p2, and u, , :
Let pc = {xc, yc} .IF u<0 THEN pc = p1ELSE IF u>1 THEN pc = p2ELSE pc = pu
.
p3 pc= `sqrt ((x3 - xc) ^ 2 + (y3 - yc) ^ 2)
. .
, , :

....