diff --git a/manim/mobject/geometry/polygram.py b/manim/mobject/geometry/polygram.py index 2a2ca133f9..fd991a1471 100644 --- a/manim/mobject/geometry/polygram.py +++ b/manim/mobject/geometry/polygram.py @@ -51,10 +51,11 @@ class Polygram(VMobject, metaclass=ConvertToOpenGL): Parameters ---------- vertex_groups - The groups of vertices making up the :class:`Polygram`. + A 2D numpy array of shape (N,3) where N is the number of points, each such points + itself being a 1D numpy array of shape (3,), for example: ``[x,y,z]``. + These points are the vertices making up the :class:`Polygram`. The first vertex in each group is repeated to close the shape. - Each point must be 3-dimensional: ``[x,y,z]`` color The color of the :class:`Polygram`. kwargs @@ -305,7 +306,17 @@ class Polygon(Polygram): Parameters ---------- vertices - The vertices of the :class:`Polygon`. + The vertices (i.e. corner points) of the :class:`Polygon`. + It is a 2D numpy array of shape (N, 3), when passed in New style. + To keep backwards compatibility, users can pass vertices either in New style or in Legacy style: + + New style: `vertices` is a 2D array of shape (N, 3) where N is the number of corner points that make up the + Polygon. Each point should be a 1D numpy array of shape (3,) representing a point in 3D space. + Example: Polygon(np.array([...])) + + Legacy style: Individual points (i.e. individual vertices) are passed one after another, separated by commas. + Example: Polygon([-5, 1.5, 0], [-2, 1.5, 0], [-3.5, -2, 0]) + kwargs Forwarded to the parent constructor. @@ -316,7 +327,7 @@ class Polygon(Polygram): class PolygonExample(Scene): def construct(self): - isosceles = Polygon([-5, 1.5, 0], [-2, 1.5, 0], [-3.5, -2, 0]) + isosceles = Polygon([[-5, 1.5, 0], [-2, 1.5, 0], [-3.5, -2, 0]]) # New style position_list = [ [4, 1, 0], # middle right [4, -2.5, 0], # bottom right @@ -325,12 +336,21 @@ def construct(self): [2, 1, 0], # middle [4, 3, 0], # top right ] - square_and_triangles = Polygon(*position_list, color=PURPLE_B) + square_and_triangles = Polygon(*position_list, color=PURPLE_B) # legacy style self.add(isosceles, square_and_triangles) """ - def __init__(self, *vertices: Point3DLike, **kwargs: Any) -> None: - super().__init__(vertices, **kwargs) + def __init__( + self, + vertices: Point3DLike_Array | Point3DLike, + *args: Point3DLike, + **kwargs: Any, + ) -> None: + if args: + all_vertices = np.array([vertices, *args], dtype=float) + else: + all_vertices = np.array(vertices, dtype=float) + super().__init__(all_vertices, **kwargs) class RegularPolygram(Polygram):