isInsidePolygon function
Requirements.Utilities.isInsidePolygon
· source
Return true if a point is inside or on a polygon (otherwise return false)
Extends Modelica.Icons.Function
Syntax
inside = isInsidePolygon(polygon, point);
Description
Returns inside = true if the vector point (point[1] = x, point[2] = y) lies inside the
polygon defined by the points polygon[:,2] (polygon[i,1] = x, polygon[i,2] = y), otherwise false.
As in distancePointToPolygon, the
last point is implicitly connected to the first one; it may also repeat the first point.
The algorithm is a crossing-number (ray-casting) test after the C code INPOLY.C (see the revisions):
every edge is oriented from its left to its right end (x1 ≤ x2), and the result is toggled for
every edge that spans the x-coordinate of the point (half-open, so that a vertex is counted once) and
passes above the point. A point inside a self-intersecting polygon is inside according to the even-odd
rule. Before the crossing test of an edge, the point is tested to lie on it (collinear within the relative
tolerance 100*Modelica.Constants.eps and within the bounding box of the edge); a point on the
boundary, an edge or a vertex, is reported as inside.
Used by distancePointToPolygon to give the distance its sign.
Revisions
2009/12/04 creation by E. Thomas from c code INPOLY.C (Freeware source code http://www.visibone.com/inpoly/inpoly.c)
2026-12-03, Model Based Innovation LLC: a point on the boundary is reported as inside on every edge, as the description says (before, it was outside on an upper edge and inside on a lower one).
Inputs
| Name | Type | Description |
|---|---|---|
polygon[…] input | Real | Polygon points (x,y) |
point[…] input | Real | Point inside, outside or on polygon |
Outputs
| Name | Type | Description |
|---|---|---|
inside output | Boolean | = true, if point is inside or on polygon, otherwise point is outside of polygon |