erlab.analysis.mask.polygon¶
Point-in-polygon algorithm.
The implementation has been adapted from the CGAL C++ library.
For most use cases, users should prefer the higher-level functions in
erlab.analysis.mask that uses this module internally.
Functions
|
Compute if a point is inside, outside, or on the boundary of a polygon. |
|
Compute whether a point lies inside a polygon using |
|
Return the index of the leftmost point of a polygon. |
|
|
|
Return the index of the rightmost point of a polygon. |
|
Classes
|
|
|
- class erlab.analysis.mask.polygon.Comparison(*values)[source]¶
Bases:
Enum- SMALLER = -1¶
- EQUAL = 0¶
- LARGER = 1¶
- class erlab.analysis.mask.polygon.Side(*values)[source]¶
Bases:
Enum- ON_UNBOUNDED_SIDE = -1¶
- ON_BOUNDARY = 0¶
- ON_BOUNDED_SIDE = 1¶
- erlab.analysis.mask.polygon.left_vertex(points)[source]¶
Return the index of the leftmost point of a polygon.
In case of a tie, the point with the smallest y-coordinate is taken.
- erlab.analysis.mask.polygon.right_vertex(points)[source]¶
Return the index of the rightmost point of a polygon.
In case of a tie, the point with the largest y-coordinate is taken.
- erlab.analysis.mask.polygon.bounded_side_bool(points, point, boundary=True)[source]¶
Compute whether a point lies inside a polygon using
bounded_side.
- erlab.analysis.mask.polygon.bounded_side(points, point)[source]¶
Compute if a point is inside, outside, or on the boundary of a polygon.
The polygon is defined by the sequence of points [first,last). Being inside is defined by the odd-even rule. If the point is on a polygon edge, a special value is returned. A simple polygon divides the plane in an unbounded and a bounded region. According to the definition points in the bounded region are inside the polygon.
- Parameters:
- Returns:
Side– Enum indicating the location of the point.- Return type:
Note
We shoot a horizontal ray from the point to the right and count the number of intersections with polygon segments. If the number of intersections is odd, the point is inside. We don’t count intersections with horizontal segments. With non-horizontal segments, the top vertex is considered to be part of the segment, but the bottom vertex is not. (Segments are half-closed).