Represents a polygon shape defined by a sequence of points.
Polygon() → PolygonPolygon() → Polygon
Polygon(points: Sequence[Vec2]) → PolygonPolygon(points: Sequence[Vec2]) → Polygon
Polygon(n: int, radius: float, centroid: Vec2 = ...) → PolygonPolygon(n: int, radius: float, centroid: Vec2 = ...) → Polygon
Represents a polygon shape defined by a sequence of points.
| Name | Description | Type |
|---|---|---|
area | Get the area of the polygon. | float |
centroid | Get or set the centroid of the polygon. | Vec2 |
is_concave | Check if the polygon is concave. | bool |
is_convex | Check if the polygon is convex. | bool |
perimeter | Get the perimeter of the polygon. | float |
points | The list of Vec2 points that define the polygon vertices. | list[Vec2] |
copy() → Polygoncopy() → PolygonReturn a copy of the polygon.
Returns
Polygon : A new polygon with the same points.
get_rect() → Rectget_rect() → RectGet the axis-aligned bounding rectangle of the polygon.
Returns
Rect : The bounding rectangle.
move(offset: Vec2) → Nonemove(offset: Vec2) → NoneMove the polygon by an offset.
Args
offset : The offset to move by.rotate(angle: float) → Nonerotate(angle: float) → NoneRotate the polygon around its centroid.
Args
angle : The rotation angle in radians.rotated(angle: float) → Polygonrotated(angle: float) → PolygonReturn a rotated copy of the polygon.
Args
angle : The rotation angle in radians.Returns
Polygon : A new polygon that is a rotated version of this polygon.
scale_by(factor: float) → Nonescale_by(factor: float) → NoneScale the polygon uniformly from its centroid.
Args
factor : The scaling factor.scale_by(factor: Vec2) → Nonescale_by(factor: Vec2) → NoneScale the polygon non-uniformly from its centroid.
Args
factor : The scaling factors for x and y.scaled_by(factor: float) → Polygonscaled_by(factor: float) → PolygonReturn a uniformly scaled copy of the polygon.
Args
factor : The scaling factor.Returns
Polygon : A new polygon that is a scaled version of this polygon.
scaled_by(factor: Vec2) → Polygonscaled_by(factor: Vec2) → PolygonReturn a non-uniformly scaled copy of the polygon.
Args
factor : The scaling factors for x and y.Returns
Polygon : A new polygon that is a scaled version of this polygon.