functiondistancePointToPolygon

Return minimum distance between a point and a polygon

Information

Syntax

(distance, polygonPoint) = minimumDistanceToPolygon(polygon, point);

Description

This function computes the minimum distance of a point to a polygon.

The polygon is defined by a set of points polygon[:,2], where polygon[i,1] is the x-coordinate of polygon point i and polygon[i,2] is the y-coordinate. The last point of the polygon can be identical to the first point, so polygon[1,:] = polygon[end,:]. If this is not the case, the function assumes that the last point polygon[end,:] is connected implicitely to the first point polygon[1,:].

The goal is to compute the minimum distance of the vector input point to polygon, where point[1] is the x-coordinate and point[2] the y-coordinate.

The function returns the minimum distance as distance.
If distance > 0, then point is inside of the polygon.
If distance < 0, then point is outside of the polygon.
If distance = 0, then point is on the polygon.
Furthermore, the point polygonPoint[2] is returned, which is a point on polygon (either on an edge or a vertex of the polygon) that is closest to input argument point.

Inputs

TypeNameDefaultDescription
Real[:,2]polygonPolygon points (x,y)
Real[2]pointPoint inside, outside or on polygon

Outputs

TypeNameDefaultDescription
RealdistanceMinimum distance of point to polygon
Real[2]polygonPointPoint on polygon that is closest to point