Polygon
A polygon shape defined by a series of points.
Constructor
-
Polygon() -
Polygon(points: Sequence[Vec2])
Parameters
points: List of Vec2 points defining the polygon vertices.
Properties
| Name | Description | Type |
|---|---|---|
points | The points that define the polygon | list[Vec2] |
perimeter | The perimeter length of the polygon. | float |
area | The area of the polygon. | float |
centroid | The centroid (geometric center) of the polygon. | Vec2 |
bounds | The axis-aligned bounding rectangle of the polygon. | Rect |
Methods
Rotate
rotate(angle: float, pivot: Vec2) → NoneRotate the polygon by a certain angle around a pivot point.
Parameters
angle: The angle in degrees to rotate the polygon.pivot: The point around which to rotate the polygon.
Translate
translate(offset: Vec2) → NoneTranslate the polygon by a certain offset.
Parameters
offset: The offset vector by which to translate the polygon.
Scale
scale(factor: float, pivot: Vec2) → NoneScale the polygon uniformly by a certain factor from a pivot point.
Parameters
factor: The scaling factor. Values less than 1.0 will shrink the polygon, while values greater than 1.0 will enlarge it.pivot: The point from which to scale the polygon.
scale(factor: Vec2, pivot: Vec2) → NoneScale the polygon non-uniformly by a certain factor from a pivot point.
Parameters
factor: The scaling factor for each axis. Values less than 1.0 will shrink the polygon, while values greater than 1.0 will enlarge it.pivot: The point from which to scale the polygon.
Copy
copy() → PolygonCreate a copy of the polygon object.
Returns
Polygon : A new copy of the polygon.