PointInPolygon
Appearance
| Environment: | Mission Scripting | |
|---|---|---|
| Function: | pointInPolygon | |
| Function Description: | Implements the classic "ray‑casting" (even‑odd) algorithm to test whether a 2‑D point lies inside an arbitrary polygon defined by a list of vertices (x, z). The function iterates over each edge of the polygon, toggling the _inside flag whenever the horizontal ray from the point crosses an edge. It returns true if the point is inside or on the boundary, otherwise false. | |
| File Location: | cmm.DCSFunctions.lua | |
| Syntax: | CMM.pointInPolygon( table _point , table _polygon ) | |
| Return Value: | boolean | |
| Parameters: | Name | Description |
| _point | Table containing at least x and z coordinates (e.g., {x = 12000, z = -65000}). | |
| _polygon | Ordered list of vertex tables each with x and z fields (e.g., {{x=0,z=0},{x=10,z=0},{x=10,z=10},{x=0,z=10}}). | |
| Example: | local inside = CMM.pointInPolygon({x=5, z=5}, {{x=0,z=0},{x=10,z=0},{x=10,z=10},{x=0,z=10}}) | |
| Example Description: | The example shows a simple square polygon and checks whether the point (5, 5) lies inside it. The function will return true for points on or inside the boundary and false otherwise. | |
| Related Functions: | ||
| Notes: | ||