Point-in-Polygon and Polygon Touches Predicates
Spatial predicates for routing: the ray-casting point-in-polygon test, three-way classification of points as interior, boundary, or exterior, and the polygon-touches predicate that distinguishes shared-boundary contact from overlap.
Tutorial
The Point-in-Polygon Predicate via Ray Casting
In a live air-routing system we must constantly answer queries such as: does a waypoint lie inside a restricted-airspace polygon? Such Boolean queries on geometric configurations are called spatial predicates.
The point-in-polygon (PIP) predicate decides whether a point lies inside a closed simple polygon . The standard algorithm is ray casting (a.k.a. the parity test):
- Cast a ray from in some direction (commonly ).
- Count the number of polygon edges the ray crosses.
- If is odd, is inside; if is even, is outside.
To test whether a horizontal ray from crosses the edge from to , we require:
(i) strictly between and : .
(ii) The edge's -coordinate at height ,
satisfies .
Illustration: triangle with .
- Edge : , ray at is not strictly between. Skip.
- Edge : ✓. ✓. Cross.
- Edge : ✓. . No.
Total crossings (odd), so is inside the triangle.