Jump to content

PointInPolygon

From CMM Wiki
Revision as of 10:12, 11 November 2025 by Ozdeadmeat (talk | contribs) (pointInPolygon – created via PowerShell script (2025-11-11T21:12:08Z))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Return to CMM Command Reference
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
_pointTable containing at least x and z coordinates (e.g., {x = 12000, z = -65000}).
_polygonOrdered 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: