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.
At a glance
14 membersReference
PYTHON APIPolygon()Overloaded function.
Polygon()
Create an empty polygon with no points.
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.
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
propertyarea: floatGet the area of the polygon.
Returns
- float — The area enclosed by the polygon.
centroid
propertycentroid: Vec2Get or set the centroid of the polygon.
Returns
- Vec2 — The center point of the polygon.
is_concave
propertyis_concave: boolCheck if the polygon is concave.
Returns
- bool — True if the polygon is concave, False otherwise.
is_convex
propertyis_convex: boolCheck if the polygon is convex.
Returns
- bool — True if the polygon is convex, False otherwise.
perimeter
propertyperimeter: floatGet the perimeter of the polygon.
Returns
- float — The total distance around the polygon.
points
propertypoints: list[Vec2]The list of Vec2 points that define the polygon vertices.
copy
methodcopy(self) -> PolygonReturn a copy of the polygon.
Returns
- Polygon — A new polygon with the same points.
get_rect
methodget_rect(self) -> RectGet the axis-aligned bounding rectangle of the polygon.
Returns
- Rect — The bounding rectangle.
move
methodmove(self, offset: Vec2) -> NoneMove the polygon by an offset.
Args
- offset (
Vec2) — The offset to move by.
rotate
methodrotate(self, angle: float) -> NoneRotate the polygon around its centroid.
Args
- angle (
float) — The rotation angle in radians.
rotated
methodrotated(self, angle: float) -> PolygonReturn 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(self, factor: float) -> Nonescale_by(self, factor: Vec2) -> NoneOverloaded function.
scale_by(self, factor: float) -> None
Scale the polygon uniformly from its centroid.
Args
- factor (
float) — The scaling factor.
scale_by(self, factor: Vec2) -> None
Scale the polygon non-uniformly from its centroid.
Args
- factor (
Vec2) — The scaling factors for x and y.
Overloaded function.
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.
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.