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


NameDescriptionType
pointsThe points that define the polygonlist[Vec2]
perimeterThe perimeter length of the polygon.float
areaThe area of the polygon.float
centroidThe centroid (geometric center) of the polygon.Vec2
boundsThe axis-aligned bounding rectangle of the polygon.Rect

Methods


Rotate

rotate(angle: float, pivot: Vec2) None

Rotate 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) None

Translate the polygon by a certain offset.

Parameters

  • offset : The offset vector by which to translate the polygon.

Scale

scale(factor: float, pivot: Vec2) None

Scale 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) None

Scale 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() Polygon

Create a copy of the polygon object.

Returns

Polygon : A new copy of the polygon.