.Modelica_Requirements.Utilities.distancePointToPolygon

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.

Interface

function distancePointToPolygon
  import Modelica.Math.Vectors.length;
  input Real polygon[:, 2] "Polygon points (x,y)";
  input Real point[2] "Point inside, outside or on polygon";
  output Real distance "Minimum distance of point to polygon";
  output Real polygonPoint[2] "Point on polygon that is closest to point";
end distancePointToPolygon;

Generated at 2024-04-26T18:16:04Z by OpenModelicaOpenModelica 1.22.3 using GenerateDoc.mos