CLASS v1.8.0

Polygon

pykraken.Polygon

Represents a polygon shape defined by a sequence of points.

More about Polygon

A polygon is a closed shape made up of connected line segments. The points define the vertices of the polygon in order. Supports various geometric operations.

Reference

PYTHON API

Constructor

method3 overloads
Polygon()
Polygon(points: Sequence[Vec2])
Polygon(n: int, radius: float, centroid: Vec2 = Vec2(0.000000, 0.000000))

Overloaded function.

  1. Polygon()

Create an empty polygon with no points.

  1. Polygon(points: Sequence[Vec2])

Create a polygon from a vector of Vec2 points.

Args

  • points (Sequence[Vec2]) — List of Vec2 points defining the polygon vertices.
  1. Polygon(n: int, radius: float, centroid: Vec2 = Vec2(0.000000, 0.000000))

Create a regular polygon with n sides inscribed in a circle of the given radius.

Args

  • n (int) — The number of sides (vertices) of the regular polygon.
  • radius (float) — The radius of the circumscribed circle for the regular polygon.
  • centroid (Vec2, optional) — The center point of the polygon. Defaults to (0, 0).

area

property
area: float

Get the area of the polygon.

Returns

  • float — The area enclosed by the polygon.

centroid

property
centroid: Vec2

Get or set the centroid of the polygon.

Returns

  • Vec2 — The center point of the polygon.

is_concave

property
is_concave: bool

Check if the polygon is concave.

Returns

  • bool — True if the polygon is concave, False otherwise.

is_convex

property
is_convex: bool

Check if the polygon is convex.

Returns

  • bool — True if the polygon is convex, False otherwise.

perimeter

property
perimeter: float

Get the perimeter of the polygon.

Returns

  • float — The total distance around the polygon.

points

property
points: list[Vec2]

The list of Vec2 points that define the polygon vertices.

copy

method
copy(self) -> Polygon

Return a copy of the polygon.

Returns

  • Polygon — A new polygon with the same points.

get_rect

method
get_rect(self) -> Rect

Get the axis-aligned bounding rectangle of the polygon.

Returns

  • Rect — The bounding rectangle.

move

method
move(self, offset: Vec2) -> None

Move the polygon by an offset.

Args

  • offset (Vec2) — The offset to move by.

rotate

method
rotate(self, angle: float) -> None

Rotate the polygon around its centroid.

Args

  • angle (float) — The rotation angle in radians.

rotated

method
rotated(self, angle: float) -> Polygon

Return a rotated copy of the polygon.

Args

  • angle (float) — The rotation angle in radians.

Returns

  • Polygon — A new polygon that is a rotated version of this polygon.

scale_by

method2 overloads
scale_by(self, factor: float) -> None
scale_by(self, factor: Vec2) -> None

Overloaded function.

  1. scale_by(self, factor: float) -> None

Scale the polygon uniformly from its centroid.

Args

  • factor (float) — The scaling factor.
  1. scale_by(self, factor: Vec2) -> None

Scale the polygon non-uniformly from its centroid.

Args

  • factor (Vec2) — The scaling factors for x and y.

scaled_by

method2 overloads
scaled_by(self, factor: float) -> Polygon
scaled_by(self, factor: Vec2) -> Polygon

Overloaded function.

  1. scaled_by(self, factor: float) -> Polygon

Return a uniformly scaled copy of the polygon.

Args

  • factor (float) — The scaling factor.

Returns

  • Polygon — A new polygon that is a scaled version of this polygon.
  1. scaled_by(self, factor: Vec2) -> Polygon

Return a non-uniformly scaled copy of the polygon.

Args

  • factor (Vec2) — The scaling factors for x and y.

Returns

  • Polygon — A new polygon that is a scaled version of this polygon.

Find your next step

Start typing to search the manual.