Skip to main content

Polygon

Description

The Polygon class, which inherits from Polygram, represents a polygon with optional rounded corners.

Details

The default drawing style for a polygon is a fill rather than a stroke.

Constructor Parameters

  • vertices (Point3D_Array): Array of vertex points, where the units are manim coordinates.
  • corner_radius (float, default=0.0): Radius for rounding corners.

Attributes

  • vertices (Point3D_Array): Array of vertex points, where the units are manim coordinates.
  • corner_radius (float): Radius for rounding corners.

Methods

  • round_corners(radius: float) -> None: Rounds the polygon's corners by reducing existing lines and inserting arcs. Only handles convex shapes with counter-clockwise orientation.

Examples

Example 1

An irregular triangle, with its corner radius set.

from smanim import *

# Note: specified vertices must be counter-clockwise to use corner-radius
p = Polygon([RIGHT, LEFT + UP, LEFT], corner_radius=0.3)
canvas.add(p)
canvas.draw(crop=True, ignore_bg=True)
Example 1

Example 2

A concave pentagon.

from smanim import *

p = Polygon([LEFT, LEFT + DOWN, DOWN * 0.5, RIGHT + DOWN, RIGHT])
canvas.add(p)
canvas.draw(crop=True, ignore_bg=True)
Example 2