Arbitrary polygon represented as a list of vertices.
The individual vertices of a polygon are mutable, but the number of vertices is fixed at construction.
Parameters: |
|
---|
Note
Several operations on polygons, such as checking for containment, or intersection, rely on knowing the convexity to select the appropriate algorithm. So, it may be beneficial to specify these values in the constructor, even if your application does not access the is_convex, or is_simple properties itself later. However, be cautious when specifying these values here, as incorrect values will likely result in incorrect results when operating on the polygon.
Note
If the polygon is mutated, the cached values of is_convex and is_simple will be invalidated.
Compare for approximate equality.
Return True if the specified point is inside the polygon.
This test can use various strategies depending on the classification of the polygon, i.e., triangular, radial, y-monotone, convex, or other.
The runtime complexity will depend on the polygon:
Triangle or best-case radial: O(1) y-monotone, convex: O(log n) other: O(n)
Parameters: |
|
---|---|
Return type: | bool |
Return a new polygon that is the convex hull of the supplied sequence of points.
If points is a polygon known to be convex, a copy of the polygon is returned.
The hull is computed using an adaptive quick-hull algorithm. The expected runtime complexity of this algorithm is O(n log h) (where h is the size of the hull), the worst case is O(n log n) when the supplied points are already nearly convex. This algorithm is especially fast when many of the supplied points are inside the resulting hull.
Parameters: |
|
---|---|
Return type: | Polygon |
Create a polygon from a sequence of points
Create a regular polygon with the specified number of vertices radius distance from the center point. Regular polygons are always convex.
Parameters: |
|
---|
Create a radial pointed star polygon with the specified number of peaks.
Parameters: |
|
---|
Given a point exterior to the polygon, return the pair of vertex points from the polygon that define the tangent lines with the specified point.
Runtime Complexity: O(log n) convex, O(n) other
Parameters: |
|
---|---|
Returns: | A tuple containing the left and right tangent points. |
Return type: | tuple of Vec2 |
The bounding box of the polygon
The geometric center point of the polygon. This point only exists for simple polygons. For non-simple polygons it is None. Note in concave polygons, this point may lie outside of the polygon itself.
If the centroid is unknown, it is calculated from the vertices and cached. If the polygon is known to be simple, this takes O(n) time. If not, then the simple polygon check is also performed, which has an expected complexity of O(n log n).
True if the polygon’s centroid has been pre-calculated and cached.
Mutating the polygon will invalidate the cached value.
True if the polygon is convex.
If this is unknown then it is calculated from the vertices of the polygon and cached. Runtime complexity: O(n)
True if the polygon is already known to be convex or not.
If this value is True, then the value of is_convex is cached and does not require additional calculation to access. Mutating the polygon will invalidate the cached value.
True if the polygon is simple, i.e., it has no self-intersections.
If this is unknown then it is calculated from the vertices of the polygon and cached. Runtime complexity: O(n) convex, O(n log n) expected for most non-convex cases, O(n^2) worst case non-convex
True if the polygon is already known to be simple or not.
If this value is True, then the value of is_simple is cached and does not require additional calculation to access. Mutating the polygon will invalidate the cached value.