-
Notifications
You must be signed in to change notification settings - Fork 18
pygeo.is_in_polygon
Daniel Flassig edited this page Jul 30, 2026
·
2 revisions
Tests whether a 2D point lies inside a polygon loop.
The is seam-free: if a planar region is divided into non-overlapping polygons, every point is reported as inside exactly one of these polygons — double counting or gaps along shared edges/points cannot occur. The test is performed in exact arithmetic on the given coordinates, without any tolerance. For a tolerance-based test against the polygon boundary use pygeo.is_on_polygon_boundary.
pygeo.is_in_polygon(point, polygon)| Parameter | Type | Description |
|---|---|---|
point |
{u,v} |
The test point in 2D. |
polygon |
{{u1,v1}, {u2,v2}, ...} |
Coordinates of the polygon loop points in 2D. The loop is automatically closed. |
| Return | Type | Description |
|---|---|---|
inside |
boolean |
true if the point lies inside the polygon (positive winding number). |
winding |
integer |
The winding number of the polygon around the test point. |
- Positive winding is always counter-clockwise (CCW). A point inside a clockwise loop receives a negative winding number and is therefore reported as outside.
- Holes are supported by connecting the outside with the hole through an arbitrary connecting edge that is traversed once in each direction (see the example). The two traversals cancel out exactly, so the connecting edge is transparent: every point — even a point exactly on the connecting edge — is classified as if the edge were not present. A hole must be traversed clockwise.
- A self-overlapping loop can produce winding numbers greater than
1(still reported as inside). - The test is exact; there is no epsilon. A point lying exactly on the boundary is classified deterministically to one side. Use
pygeo.is_on_polygon_boundaryto detect boundary proximity within a tolerance.
local inside, winding = pygeo.is_in_polygon(
{5, 5},
{{0, 0}, {10, 0}, {10, 10}, {0, 10}}
)
-- inside -> true, winding -> 1A square with a square hole, encoded as one loop with a doubled connecting edge:
local inside = pygeo.is_in_polygon(
{10, 10},
{
{0, 0}, {20, 0}, {20, 20}, {0, 20}, -- outer loop (CCW)
{0, 0}, -- back to the start point
{4, 4}, {4, 16}, {16, 16}, {16, 4}, -- hole (CW)
{4, 4}, -- hole closed;
-- the implicit edge back to {0, 0} doubles the
-- connecting edge
}
)
-- inside -> false (the point lies in the hole)Minimum PYTHA Version: V26