Polygon

Represents a polygon shape defined by a sequence of points.

Constructor

Represents a polygon shape defined by a sequence of points.

Properties


NameDescriptionType
pointsThe list of Vec2 points that define the polygon vertices.list[Vec2]
perimeterGet the perimeter of the polygon.float
areaGet the area of the polygon.float
centroidGet the centroid of the polygon.Vec2
is_convexCheck if the polygon is convex.bool
is_concaveCheck if the polygon is concave.bool

Methods


Get Rect

get_rect() Rect

Get the axis-aligned bounding rectangle of the polygon.

Returns

Rect : The bounding rectangle.

Copy

copy() Polygon

Return a copy of the polygon.

Returns

Polygon : A new polygon with the same points.

Rotate

rotate(angle: float, pivot: Vec2 = ...) 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).

Translate

translate(offset: Vec2) None

Move the polygon by an offset.

Args

  • offset : The offset to move by.

Scale

scale(factor: float, pivot: Vec2 = ...) 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: Vec2 = ...) 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).