VertexRegularPolygon

Regular n-sided polygon as a VertexLoop

Generates a regular polygon with any number of sides, with vertices distributed along its perimeter. The num_vertices parameter is crucial for morphing - shapes with the same num_vertices can morph smoothly between each other.

Constructor

VertexRegularPolygon(
    center: float = Point2D(x=0, y=0),
    size: float = 50.0,
    num_sides: int = 6,
    num_vertices: int = 128,
    rotation: float = 0.0
)

Create a regular polygon as a vertex loop

Parameters

cx
Center x coordinate
cy
Center y coordinate
size
Distance from center to vertices (circumradius)
num_sides
Number of polygon sides (3=triangle, 4=square, etc.)
num_vertices
Number of vertices distributed along perimeter (important for morphing!)
rotation
Rotation in degrees (0° = North, 90° = East, Svan2D convention)

Methods

area

area()

Calculate the signed area of the loop

bounds

bounds()

Calculate bounding box (min_x, min_y, max_x, max_y)

centroid

centroid()

Calculate the centroid (geometric center) of the vertices

is_clockwise

is_clockwise()

Check if the loop has clockwise winding (negative area)

reverse

reverse()

Return a new VertexLoop with reversed vertex order

rotate

rotate(
    angle_degrees: float,
    center: Optional[Point2D] = None
) -> VertexLoop

Rotate vertices in-place by angle_degrees around center

Parameters

angle_degrees
Rotation angle in degrees (positive = counter-clockwise)
center
Center of rotation (default is origin) Returns self for method chaining.

scale

scale(sx: float, sy: Optional[float] = None) -> VertexLoop

Scale vertices in-place by (sx, sy)

translate

translate(dx: float, dy: float) -> VertexLoop

Translate vertices in-place by (dx, dy)

Properties

closed
Whether this loop is closed
vertices
Get vertices as list of tuples