Polygon

Represents a polygon shape defined by a sequence of points.

Constructor

Represents a polygon shape defined by a sequence of points.

Properties


NameDescriptionType
areaGet the area of the polygon.float
centroidGet the centroid of the polygon.Vec2
perimeterGet the perimeter of the polygon.float
pointsThe list of Vec2 points that define the polygon vertices.list[Vec2]

Methods


Copy

copy() Polygon

Return a copy of the polygon.

Returns

Polygon : A new polygon with the same points.

Get Rect

get_rect() Rect

Get the axis-aligned bounding rectangle of the polygon. Returns

Rect : The bounding rectangle.

Rotate

rotate(angle: SupportsFloat, pivot: Any = None) None

Rotate the polygon around a pivot point.

Args

  • angle : The rotation angle in radians.
  • pivot : The normalized point relative to the polygon's bounding box to rotate around. Defaults to center (0.5, 0.5).

Scale

scale(factor: SupportsFloat, pivot: Any = None) None

Scale the polygon uniformly from a pivot point.

Args

  • factor : The scaling factor.
  • pivot : The normalized point relative to the polygon's bounding box to scale from. Defaults to center (0.5, 0.5).

scale(factor: Vec2, pivot: Any = None) None

Scale the polygon non-uniformly from a pivot point.

Args

  • factor : The scaling factors for x and y.
  • pivot : The normalized point relative to the polygon's bounding box to scale from. Defaults to center (0.5, 0.5).

Translate

translate(offset: Vec2) None

Move the polygon by an offset.

Args

  • offset : The offset to move by.