API 参考:几何图形(geometry)

共 57 个类,按字母排序。每个类含中文说明、继承链、参数表与上手示例,API 文档由 autodoc 从 manim v0.21.0 源码自动生成;带完整中文精讲的类见 API 索引。

Angle

两条线的夹角图形:自动找交点、按半径画出夹角弧,可标注度数,几何作图必备。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Angle"; }

参数

line1

—,Line

line2

—,Line

radius

None,float | None

quadrant

(1, 1),AngleQuadrant

other_angle

False,bool

dot

False,bool

dot_radius

None,float | None

dot_distance

0.55,float

dot_color

ManimColor('#FFFFFF'),ParsableManimColor

elbow

False,bool

快速上手

angle = Angle(line1, line2, radius=0.5)

API 文档

class manim.Angle(line1: Line, line2: Line, radius: float | None = None, quadrant: AngleQuadrant = (1, 1), other_angle: bool = False, dot: bool = False, dot_radius: float | None = None, dot_distance: float = 0.55, dot_color: ParsableManimColor = ManimColor('#FFFFFF'), elbow: bool = False, **kwargs: Any)

基类:VMobject

A circular arc or elbow-type mobject representing an angle of two lines.

Parameters

line1 :

The first line.

line2 :

The second line.

radius :

The radius of the Arc.

quadrant

A sequence of two int numbers determining which of the 4 quadrants should be used. The first value indicates whether to anchor the arc on the first line closer to the end point (1) or start point (-1), and the second value functions similarly for the end (1) or start (-1) of the second line. Possibilities: (1,1), (-1,1), (1,-1), (-1,-1).

other_angle :

Toggles between the two possible angles defined by two points and an arc center. If set to False (default), the arc will always go counterclockwise from the point on line1 until the point on line2 is reached. If set to True, the angle will go clockwise from line1 to line2.

dot

Allows for a Dot in the arc. Mainly used as an convention to indicate a right angle. The dot can be customized in the next three parameters.

dot_radius

The radius of the Dot. If not specified otherwise, this radius will be 1/10 of the arc radius.

dot_distance

Relative distance from the center to the arc: 0 puts the dot in the center and 1 on the arc itself.

dot_color

The color of the Dot.

elbow

Produces an elbow-type mobject indicating a right angle, see RightAngle for more information and a shorthand.

**kwargs

Further keyword arguments that are passed to the constructor of Arc or Elbow.

Examples

The first example shows some right angles with a dot in the middle while the second example shows all 8 possible angles defined by two lines.

class RightArcAngleExample(Scene):
    def construct(self):
        line1 = Line( LEFT, RIGHT )
        line2 = Line( DOWN, UP )
        rightarcangles = [
            Angle(line1, line2, dot=True),
            Angle(line1, line2, radius=0.4, quadrant=(1,-1), dot=True, other_angle=True),
            Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8, dot=True, dot_color=YELLOW, dot_radius=0.04, other_angle=True),
            Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED, dot=True, dot_color=GREEN, dot_radius=0.08),
        ]
        plots = VGroup()
        for angle in rightarcangles:
            plot=VGroup(line1.copy(),line2.copy(), angle)
            plots.add(plot)
        plots.arrange(buff=1.5)
        self.add(plots)
class AngleExample(Scene):
    def construct(self):
        line1 = Line( LEFT + (1/3) * UP, RIGHT + (1/3) * DOWN )
        line2 = Line( DOWN + (1/3) * RIGHT, UP + (1/3) * LEFT )
        angles = [
            Angle(line1, line2),
            Angle(line1, line2, radius=0.4, quadrant=(1,-1), other_angle=True),
            Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8, other_angle=True),
            Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED),
            Angle(line1, line2, other_angle=True),
            Angle(line1, line2, radius=0.4, quadrant=(1,-1)),
            Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8),
            Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED, other_angle=True),
        ]
        plots = VGroup()
        for angle in angles:
            plot=VGroup(line1.copy(),line2.copy(), angle)
            plots.add(VGroup(plot,SurroundingRectangle(plot, buff=0.3)))
        plots.arrange_in_grid(rows=2,buff=1)
        self.add(plots)
class FilledAngle(Scene):
    def construct(self):
        l1 = Line(ORIGIN, 2 * UP + RIGHT).set_color(GREEN)
        l2 = (
            Line(ORIGIN, 2 * UP + RIGHT)
            .set_color(GREEN)
            .rotate(-20 * DEGREES, about_point=ORIGIN)
        )
        norm = l1.get_length()
        a1 = Angle(l1, l2, other_angle=True, radius=norm - 0.5).set_color(GREEN)
        a2 = Angle(l1, l2, other_angle=True, radius=norm).set_color(GREEN)
        q1 = a1.points #  save all coordinates of points of angle a1
        q2 = a2.reverse_direction().points  #  save all coordinates of points of angle a1 (in reversed direction)
        pnts = np.concatenate([q1, q2, q1[0].reshape(1, 3)])  # adds points and ensures that path starts and ends at same point
        mfill = VMobject().set_color(ORANGE)
        mfill.set_points_as_corners(pnts).set_fill(GREEN, opacity=1)
        self.add(l1, l2)
        self.add(mfill)
static from_three_points(A: Point3DLike, B: Point3DLike, C: Point3DLike, **kwargs: Any) → Angle

The angle between the lines AB and BC.

This constructs the angle \(\\angle ABC\).

Parameters
A

The endpoint of the first angle leg

B

The vertex of the angle

C

The endpoint of the second angle leg

**kwargs

Further keyword arguments are passed to Angle

Returns

The Angle calculated from the three points

Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8), Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED, other_angle=True),

Examples
class AngleFromThreePointsExample(Scene):
    def construct(self):
        sample_angle = Angle.from_three_points(UP, ORIGIN, LEFT)
        red_angle = Angle.from_three_points(LEFT + UP, ORIGIN, RIGHT, radius=.8, quadrant=(-1,-1), color=RED, stroke_width=8, other_angle=True)
        self.add(red_angle, sample_angle)
get_lines() → VGroup

Get the lines forming an angle of the Angle class.

Returns
VGroup

A VGroup containing the lines that form the angle of the Angle class.

Examples
>>> line_1, line_2 = Line(ORIGIN, RIGHT), Line(ORIGIN, UR)
>>> angle = Angle(line_1, line_2)
>>> angle.get_lines()
VGroup(Line, Line)
get_value(degrees: bool = False) → float

Get the value of an angle of the Angle class.

Parameters
degrees

A boolean to decide the unit (deg/rad) in which the value of the angle is returned.

Returns
float

The value in degrees/radians of an angle of the Angle class.

Examples
class GetValueExample(Scene):
    def construct(self):
        line1 = Line(LEFT+(1/3)*UP, RIGHT+(1/3)*DOWN)
        line2 = Line(DOWN+(1/3)*RIGHT, UP+(1/3)*LEFT)

        angle = Angle(line1, line2, radius=0.4)

        value = DecimalNumber(angle.get_value(degrees=True), unit=r"^{\circ}")
        value.next_to(angle, UR)

        self.add(line1, line2, angle, value)

AnnotationDot

带描边强调的小圆点,比普通 Dot 在复杂背景上更醒目,常用于标记点。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; "Arc" -> "Circle"; "Circle" -> "Dot"; "Dot" -> "AnnotationDot"; }

参数

radius

0.10400000000000001,float

stroke_width

5,float

stroke_color

ManimColor('#FFFFFF'),ParsableManimColor

fill_color

ManimColor('#58C4DD'),ParsableManimColor

API 文档

class manim.AnnotationDot(radius: float = 0.10400000000000001, stroke_width: float = 5, stroke_color: ManimColor | int | str | NDArray[int64] | tuple[int, int, int] | NDArray[float64] | tuple[float, float, float] | tuple[int, int, int, int] | tuple[float, float, float, float] = ManimColor('#FFFFFF'), fill_color: ManimColor | int | str | NDArray[int64] | tuple[int, int, int] | NDArray[float64] | tuple[float, float, float] | tuple[int, int, int, int] | tuple[float, float, float, float] = ManimColor('#58C4DD'), **kwargs: Any)

基类:Dot

A dot with bigger radius and bold stroke to annotate scenes.

AnnularSector

扇环(圆环的一段):内外半径 + 起止角度,饼图环图的基础件。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; "Arc" -> "AnnularSector"; }

参数

inner_radius

1,float

outer_radius

2,float

angle

1.5707963267948966,float

start_angle

0,float

fill_opacity

1,float

stroke_width

0,float

color

ManimColor('#FFFFFF'),ParsableManimColor

快速上手

s = AnnularSector(inner_radius=1, outer_radius=2, angle=PI/2)

API 文档

class manim.AnnularSector(inner_radius: float = 1, outer_radius: float = 2, angle: float = 1.5707963267948966, start_angle: float = 0, fill_opacity: float = 1, stroke_width: float = 0, color: ManimColor | int | str | NDArray[int64] | tuple[int, int, int] | NDArray[float64] | tuple[float, float, float] | tuple[int, int, int, int] | tuple[float, float, float, float] = ManimColor('#FFFFFF'), **kwargs: Any)

基类:Arc

A sector of an annulus.

Parameters

inner_radius

The inside radius of the Annular Sector.

outer_radius

The outside radius of the Annular Sector.

angle

The clockwise angle of the Annular Sector.

start_angle

The starting clockwise angle of the Annular Sector.

fill_opacity

The opacity of the color filled in the Annular Sector.

stroke_width

The stroke width of the Annular Sector.

color

The color filled into the Annular Sector.

Examples

class AnnularSectorExample(Scene):
    def construct(self):
        # Changes background color to clearly visualize changes in fill_opacity.
        self.camera.background_color = WHITE

        # The default parameter start_angle is 0, so the AnnularSector starts from the +x-axis.
        s1 = AnnularSector(color=YELLOW).move_to(2 * UL)

        # Different inner_radius and outer_radius than the default.
        s2 = AnnularSector(inner_radius=1.5, outer_radius=2, angle=45 * DEGREES, color=RED).move_to(2 * UR)

        # fill_opacity is typically a number > 0 and <= 1. If fill_opacity=0, the AnnularSector is transparent.
        s3 = AnnularSector(inner_radius=1, outer_radius=1.5, angle=PI, fill_opacity=0.25, color=BLUE).move_to(2 * DL)

        # With a negative value for the angle, the AnnularSector is drawn clockwise from the start value.
        s4 = AnnularSector(inner_radius=1, outer_radius=1.5, angle=-3 * PI / 2, color=GREEN).move_to(2 * DR)

        self.add(s1, s2, s3, s4)
generate_points() → Self

Initializes points and therefore the shape.

Gets called upon creation. This is an empty method that can be implemented by subclasses.

Annulus

完整圆环:内半径 + 外半径,甜甜圈形状。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; "Arc" -> "Circle"; "Circle" -> "Annulus"; }

参数

inner_radius

1,float

outer_radius

2,float

fill_opacity

1,float

stroke_width

0,float

color

ManimColor('#FFFFFF'),ParsableManimColor

mark_paths_closed

False,bool

API 文档

class manim.Annulus(inner_radius: float = 1, outer_radius: float = 2, fill_opacity: float = 1, stroke_width: float = 0, color: ManimColor | int | str | NDArray[int64] | tuple[int, int, int] | NDArray[float64] | tuple[float, float, float] | tuple[int, int, int, int] | tuple[float, float, float, float] = ManimColor('#FFFFFF'), mark_paths_closed: bool = False, **kwargs: Any)

基类:Circle

Region between two concentric Circles.

Parameters

inner_radius

The radius of the inner Circle.

outer_radius

The radius of the outer Circle.

kwargs

Additional arguments to be passed to Annulus

Examples

class AnnulusExample(Scene):
    def construct(self):
        annulus_1 = Annulus(inner_radius=0.5, outer_radius=1).shift(UP)
        annulus_2 = Annulus(inner_radius=0.3, outer_radius=0.6, color=RED).next_to(annulus_1, DOWN)
        self.add(annulus_1, annulus_2)
generate_points() → Self

Initializes points and therefore the shape.

Gets called upon creation. This is an empty method that can be implemented by subclasses.

Arc

圆弧:半径 + 起始角 + 张角,所有曲线类图形(Circle、Sector……)的祖宗。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; }

参数

radius

1.0,float | None

start_angle

0,float

angle

1.5707963267948966,float

num_components

9,int

arc_center

array([0., 0., 0.]),Point3DLike

快速上手

arc = Arc(radius=2, start_angle=0, angle=PI)

API 文档

class manim.Arc(radius: float | None = 1.0, start_angle: float = 0, angle: float = 1.5707963267948966, num_components: int = 9, arc_center: Point3DLike = array([0., 0., 0.]), **kwargs: Any)

基类:TipableVMobject

A circular arc.

Examples

A simple arc of angle Pi.

class ArcExample(Scene):
    def construct(self):
        self.add(Arc(angle=PI))
generate_points() → Self

Initializes points and therefore the shape.

Gets called upon creation. This is an empty method that can be implemented by subclasses.

get_arc_center(warning: bool = True) → Point3D

Looks at the normals to the first two anchors, and finds their intersection points

ArcBetweenPoints

过两点的一段圆弧:自动选半径让弧经过两点,画「连接箭头」或「跳跃路径」常用。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; "Arc" -> "ArcBetweenPoints"; }

参数

start

—,Point3DLike

end

—,Point3DLike

angle

1.5707963267948966,float

radius

None,float | None

快速上手

arc = ArcBetweenPoints(a.get_center(), b.get_center())

API 文档

class manim.ArcBetweenPoints(start: Point3DLike, end: Point3DLike, angle: float = 1.5707963267948966, radius: float | None = None, **kwargs: Any)

基类:Arc

Inherits from Arc and additionally takes 2 points between which the arc is spanned.

Example

class ArcBetweenPointsExample(Scene):
    def construct(self):
        circle = Circle(radius=2, stroke_color=GREY)
        dot_1 = Dot(color=GREEN).move_to([2, 0, 0]).scale(0.5)
        dot_1_text = Tex("(2,0)").scale(0.5).next_to(dot_1, RIGHT).set_color(BLUE)
        dot_2 = Dot(color=GREEN).move_to([0, 2, 0]).scale(0.5)
        dot_2_text = Tex("(0,2)").scale(0.5).next_to(dot_2, UP).set_color(BLUE)
        arc= ArcBetweenPoints(start=2 * RIGHT, end=2 * UP, stroke_color=YELLOW)
        self.add(circle, dot_1, dot_2, dot_1_text, dot_2_text)
        self.play(Create(arc))

ArcPolygon

边为圆弧的多边形:顶点之间用弧连接而非直线,呈现「鼓包」轮廓。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "ArcPolygon"; }

参数

angle

0.7853981633974483,float

radius

None,float | None

arc_config

None,list[dict] | None

API 文档

class manim.ArcPolygon(*vertices: Point3DLike, angle: float = 0.7853981633974483, radius: float | None = None, arc_config: list[dict] | None = None, **kwargs: Any)

基类:VMobject

A generalized polygon allowing for points to be connected with arcs.

This version tries to stick close to the way Polygon is used. Points can be passed to it directly which are used to generate the according arcs (using ArcBetweenPoints). An angle or radius can be passed to it to use across all arcs, but to configure arcs individually an arc_config list has to be passed with the syntax explained below.

Parameters

vertices

A list of vertices, start and end points for the arc segments.

angle

The angle used for constructing the arcs. If no other parameters are set, this angle is used to construct all arcs.

radius

The circle radius used to construct the arcs. If specified, overrides the specified angle.

arc_config

When passing a dict, its content will be passed as keyword arguments to ArcBetweenPoints. Otherwise, a list of dictionaries containing values that are passed as keyword arguments for every individual arc can be passed.

kwargs

Further keyword arguments that are passed to the constructor of VMobject.

Attributes

arcslist

The arcs created from the input parameters:

>>> from manim import ArcPolygon
>>> ap = ArcPolygon([0, 0, 0], [2, 0, 0], [0, 2, 0])
>>> ap.arcs
[ArcBetweenPoints, ArcBetweenPoints, ArcBetweenPoints]

小技巧

Two instances of ArcPolygon can be transformed properly into one another as well. Be advised that any arc initialized with angle=0 will actually be a straight line, so if a straight section should seamlessly transform into an arced section or vice versa, initialize the straight section with a negligible angle instead (such as angle=0.0001).

备注

There is an alternative version (ArcPolygonFromArcs) that is instantiated with pre-defined arcs.

See Also

ArcPolygonFromArcs

Examples

class SeveralArcPolygons(Scene):
    def construct(self):
        a = [0, 0, 0]
        b = [2, 0, 0]
        c = [0, 2, 0]
        ap1 = ArcPolygon(a, b, c, radius=2)
        ap2 = ArcPolygon(a, b, c, angle=45*DEGREES)
        ap3 = ArcPolygon(a, b, c, arc_config={'radius': 1.7, 'color': RED})
        ap4 = ArcPolygon(a, b, c, color=RED, fill_opacity=1,
                                    arc_config=[{'radius': 1.7, 'color': RED},
                                    {'angle': 20*DEGREES, 'color': BLUE},
                                    {'radius': 1}])
        ap_group = VGroup(ap1, ap2, ap3, ap4).arrange()
        self.play(*[Create(ap) for ap in [ap1, ap2, ap3, ap4]])
        self.wait()

For further examples see ArcPolygonFromArcs.

ArcPolygonFromArcs

用现成 Arc 对象拼成多边形,边完全由你给的弧决定。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "ArcPolygonFromArcs"; }

API 文档

class manim.ArcPolygonFromArcs(*arcs: Arc | ArcBetweenPoints, **kwargs: Any)

基类:VMobject

A generalized polygon allowing for points to be connected with arcs.

This version takes in pre-defined arcs to generate the arcpolygon and introduces little new syntax. However unlike Polygon it can't be created with points directly.

For proper appearance the passed arcs should connect seamlessly: [a,b][b,c][c,a]

If there are any gaps between the arcs, those will be filled in with straight lines, which can be used deliberately for any straight sections. Arcs can also be passed as straight lines such as an arc initialized with angle=0.

Parameters

arcs

These are the arcs from which the arcpolygon is assembled.

kwargs

Keyword arguments that are passed to the constructor of VMobject. Affects how the ArcPolygon itself is drawn, but doesn't affect passed arcs.

Attributes

arcs

The arcs used to initialize the ArcPolygonFromArcs:

>>> from manim import ArcPolygonFromArcs, Arc, ArcBetweenPoints
>>> ap = ArcPolygonFromArcs(Arc(), ArcBetweenPoints([1,0,0], [0,1,0]), Arc())
>>> ap.arcs
[Arc, ArcBetweenPoints, Arc]

小技巧

Two instances of ArcPolygon can be transformed properly into one another as well. Be advised that any arc initialized with angle=0 will actually be a straight line, so if a straight section should seamlessly transform into an arced section or vice versa, initialize the straight section with a negligible angle instead (such as angle=0.0001).

备注

There is an alternative version (ArcPolygon) that can be instantiated with points.

参见

ArcPolygon

Examples

One example of an arcpolygon is the Reuleaux triangle. Instead of 3 straight lines connecting the outer points, a Reuleaux triangle has 3 arcs connecting those points, making a shape with constant width.

Passed arcs are stored as submobjects in the arcpolygon. This means that the arcs are changed along with the arcpolygon, for example when it's shifted, and these arcs can be manipulated after the arcpolygon has been initialized.

Also both the arcs contained in an ArcPolygonFromArcs, as well as the arcpolygon itself are drawn, which affects draw time in Create for example. In most cases the arcs themselves don't need to be drawn, in which case they can be passed as invisible.

class ArcPolygonExample(Scene):
    def construct(self):
        arc_conf = {"stroke_width": 0}
        poly_conf = {"stroke_width": 10, "stroke_color": BLUE,
              "fill_opacity": 1, "color": PURPLE}
        a = [-1, 0, 0]
        b = [1, 0, 0]
        c = [0, np.sqrt(3), 0]
        arc0 = ArcBetweenPoints(a, b, radius=2, **arc_conf)
        arc1 = ArcBetweenPoints(b, c, radius=2, **arc_conf)
        arc2 = ArcBetweenPoints(c, a, radius=2, **arc_conf)
        reuleaux_tri = ArcPolygonFromArcs(arc0, arc1, arc2, **poly_conf)
        self.play(FadeIn(reuleaux_tri))
        self.wait(2)

The arcpolygon itself can also be hidden so that instead only the contained arcs are drawn. This can be used to easily debug arcs or to highlight them.

class ArcPolygonExample2(Scene):
    def construct(self):
        arc_conf = {"stroke_width": 3, "stroke_color": BLUE,
            "fill_opacity": 0.5, "color": GREEN}
        poly_conf = {"color": None}
        a = [-1, 0, 0]
        b = [1, 0, 0]
        c = [0, np.sqrt(3), 0]
        arc0 = ArcBetweenPoints(a, b, radius=2, **arc_conf)
        arc1 = ArcBetweenPoints(b, c, radius=2, **arc_conf)
        arc2 = ArcBetweenPoints(c, a, radius=2, stroke_color=RED)
        reuleaux_tri = ArcPolygonFromArcs(arc0, arc1, arc2, **poly_conf)
        self.play(FadeIn(reuleaux_tri))
        self.wait(2)

Arrow

带箭头的直线:start/end + 箭尖样式 buff 可调,是最常用的指向性图形。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Line"; "Line" -> "Arrow"; }

参数

stroke_width

6,float

buff

0.25,float

max_tip_length_to_length_ratio

0.25,float

max_stroke_width_to_length_ratio

5,float

快速上手

arrow = Arrow(LEFT, RIGHT, buff=0.1)

API 文档

class manim.Arrow(*args: Any, stroke_width: float = 6, buff: float = 0.25, max_tip_length_to_length_ratio: float = 0.25, max_stroke_width_to_length_ratio: float = 5, **kwargs: Any)

基类:Line

An arrow.

Parameters

args

Arguments to be passed to Line.

stroke_width

The thickness of the arrow. Influenced by max_stroke_width_to_length_ratio.

buff

The distance of the arrow from its start and end points.

max_tip_length_to_length_ratio

tip_length scales with the length of the arrow. Increasing this ratio raises the max value of tip_length.

max_stroke_width_to_length_ratio

stroke_width scales with the length of the arrow. Increasing this ratio ratios the max value of stroke_width.

kwargs

Additional arguments to be passed to Line.

Examples

from manim.mobject.geometry.tips import ArrowSquareTip
class ArrowExample(Scene):
    def construct(self):
        arrow_1 = Arrow(start=RIGHT, end=LEFT, color=GOLD)
        arrow_2 = Arrow(start=RIGHT, end=LEFT, color=GOLD, tip_shape=ArrowSquareTip).shift(DOWN)
        g1 = Group(arrow_1, arrow_2)

        # the effect of buff
        square = Square(color=MAROON_A)
        arrow_3 = Arrow(start=LEFT, end=RIGHT)
        arrow_4 = Arrow(start=LEFT, end=RIGHT, buff=0).next_to(arrow_1, UP)
        g2 = Group(arrow_3, arrow_4, square)

        # a shorter arrow has a shorter tip and smaller stroke width
        arrow_5 = Arrow(start=ORIGIN, end=config.top).shift(LEFT * 4)
        arrow_6 = Arrow(start=config.top + DOWN, end=config.top).shift(LEFT * 3)
        g3 = Group(arrow_5, arrow_6)

        self.add(Group(g1, g2, g3).arrange(buff=2))
class ArrowExample(Scene):
    def construct(self):
        left_group = VGroup()
        # As buff increases, the size of the arrow decreases.
        for buff in np.arange(0, 2.2, 0.45):
            left_group += Arrow(buff=buff, start=2 * LEFT, end=2 * RIGHT)
        # Required to arrange arrows.
        left_group.arrange(DOWN)
        left_group.move_to(4 * LEFT)

        middle_group = VGroup()
        # As max_stroke_width_to_length_ratio gets bigger,
        # the width of stroke increases.
        for i in np.arange(0, 5, 0.5):
            middle_group += Arrow(max_stroke_width_to_length_ratio=i)
        middle_group.arrange(DOWN)

        UR_group = VGroup()
        # As max_tip_length_to_length_ratio increases,
        # the length of the tip increases.
        for i in np.arange(0, 0.3, 0.1):
            UR_group += Arrow(max_tip_length_to_length_ratio=i)
        UR_group.arrange(DOWN)
        UR_group.move_to(4 * RIGHT + 2 * UP)

        DR_group = VGroup()
        DR_group += Arrow(start=LEFT, end=RIGHT, color=BLUE, tip_shape=ArrowSquareTip)
        DR_group += Arrow(start=LEFT, end=RIGHT, color=BLUE, tip_shape=ArrowSquareFilledTip)
        DR_group += Arrow(start=LEFT, end=RIGHT, color=YELLOW, tip_shape=ArrowCircleTip)
        DR_group += Arrow(start=LEFT, end=RIGHT, color=YELLOW, tip_shape=ArrowCircleFilledTip)
        DR_group.arrange(DOWN)
        DR_group.move_to(4 * RIGHT + 2 * DOWN)

        self.add(left_group, middle_group, UR_group, DR_group)
get_default_tip_length() → float

Returns the default tip_length of the arrow.

Examples
>>> Arrow().get_default_tip_length()
0.35
get_normal_vector() → Vector3D

Returns the normal of a vector.

Examples
>>> np.round(Arrow().get_normal_vector()) + 0. # add 0. to avoid negative 0 in output
array([ 0.,  0., -1.])
reset_normal_vector() → Self

Resets the normal of a vector

scale(factor: float, scale_tips: bool = False, **kwargs: Any) → Self

Scale an arrow, but keep stroke width and arrow tip size fixed.

参见

scale()

Examples
>>> arrow = Arrow(np.array([-1, -1, 0]), np.array([1, 1, 0]), buff=0)
>>> scaled_arrow = arrow.scale(2)
>>> np.round(scaled_arrow.get_start_and_end(), 8) + 0
array([[-2., -2.,  0.],
       [ 2.,  2.,  0.]])
>>> arrow.tip.length == scaled_arrow.tip.length
True

Manually scaling the object using the default method scale() does not have the same properties:

>>> new_arrow = Arrow(np.array([-1, -1, 0]), np.array([1, 1, 0]), buff=0)
>>> another_scaled_arrow = VMobject.scale(new_arrow, 2)
>>> another_scaled_arrow.tip.length == arrow.tip.length
False

ArrowCircleFilledTip

圆形实心箭尖样式类:配合 Arrow 的 tip_shape 使用(ArrowCircleTip 的实心版)。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; "Arc" -> "Circle"; "Circle" -> "ArrowTip"; "ArrowTip" -> "ArrowCircleTip"; "ArrowCircleTip" -> "ArrowCircleFilledTip"; }

参数

fill_opacity

1,float

stroke_width

0,float

API 文档

class manim.ArrowCircleFilledTip(fill_opacity: float = 1, stroke_width: float = 0, **kwargs: Any)

基类:ArrowCircleTip

Circular arrow tip with filled tip.

ArrowCircleTip

空心圆形箭尖样式类:把箭头末端换成小圆圈,思维导图风。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; "Arc" -> "Circle"; "Circle" -> "ArrowTip"; "ArrowTip" -> "ArrowCircleTip"; }

参数

fill_opacity

0,float

stroke_width

3,float

length

0.35,float

start_angle

3.141592653589793,float

API 文档

class manim.ArrowCircleTip(fill_opacity: float = 0, stroke_width: float = 3, length: float = 0.35, start_angle: float = 3.141592653589793, **kwargs: Any)

基类:ArrowTip, Circle

Circular arrow tip.

ArrowSquareFilledTip

方形实心箭尖样式类。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "Polygon"; "Polygon" -> "Rectangle"; "Rectangle" -> "Square"; "Square" -> "ArrowTip"; "ArrowTip" -> "ArrowSquareTip"; "ArrowSquareTip" -> "ArrowSquareFilledTip"; }

参数

fill_opacity

1,float

stroke_width

0,float

API 文档

class manim.ArrowSquareFilledTip(fill_opacity: float = 1, stroke_width: float = 0, **kwargs: Any)

基类:ArrowSquareTip

Square arrow tip with filled tip.

ArrowSquareTip

空心方形箭尖样式类。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "Polygon"; "Polygon" -> "Rectangle"; "Rectangle" -> "Square"; "Square" -> "ArrowTip"; "ArrowTip" -> "ArrowSquareTip"; }

参数

fill_opacity

0,float

stroke_width

3,float

length

0.35,float

start_angle

3.141592653589793,float

API 文档

class manim.ArrowSquareTip(fill_opacity: float = 0, stroke_width: float = 3, length: float = 0.35, start_angle: float = 3.141592653589793, **kwargs: Any)

基类:ArrowTip, Square

Square arrow tip.

ArrowTip

所有箭尖样式的基类:自定义箭尖就继承它实现 set_points(),length/width 属性定义尺寸。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "ArrowTip"; }

API 文档

class manim.ArrowTip(*args: Any, **kwargs: Any)

基类:VMobject

Base class for arrow tips.

Examples

Cannot be used directly, only intended for inheritance:

>>> tip = ArrowTip()
Traceback (most recent call last):
...
NotImplementedError: Has to be implemented in inheriting subclasses.

Instead, use one of the pre-defined ones, or make a custom one like this:

>>> from manim import RegularPolygon, Arrow
>>> class MyCustomArrowTip(ArrowTip, RegularPolygon):
...     def __init__(self, length=0.35, **kwargs):
...         RegularPolygon.__init__(self, n=5, **kwargs)
...         self.width = length
...         self.stretch_to_fit_height(length)
>>> arr = Arrow(
...     np.array([-2, -2, 0]), np.array([2, 2, 0]), tip_shape=MyCustomArrowTip
... )
>>> isinstance(arr.tip, RegularPolygon)
True
>>> from manim import Scene, Create
>>> class CustomTipExample(Scene):
...     def construct(self):
...         self.play(Create(arr))

Using a class inherited from ArrowTip to get a non-filled tip is a shorthand to manually specifying the arrow tip style as follows:

>>> arrow = Arrow(np.array([0, 0, 0]), np.array([1, 1, 0]),
...               tip_style={'fill_opacity': 0, 'stroke_width': 3})

The following example illustrates the usage of all of the predefined arrow tips.

class ArrowTipsShowcase(Scene):
    def construct(self):
        tip_names = [
            'Default (YELLOW)', 'ArrowTriangleTip', 'Default', 'ArrowSquareTip',
            'ArrowSquareFilledTip', 'ArrowCircleTip', 'ArrowCircleFilledTip', 'StealthTip'
        ]

        big_arrows = [
            Arrow(start=[-4, 3.5, 0], end=[2, 3.5, 0], color=YELLOW),
            Arrow(start=[-4, 2.5, 0], end=[2, 2.5, 0], tip_shape=ArrowTriangleTip),
            Arrow(start=[-4, 1.5, 0], end=[2, 1.5, 0]),
            Arrow(start=[-4, 0.5, 0], end=[2, 0.5, 0], tip_shape=ArrowSquareTip),

            Arrow([-4, -0.5, 0], [2, -0.5, 0], tip_shape=ArrowSquareFilledTip),
            Arrow([-4, -1.5, 0], [2, -1.5, 0], tip_shape=ArrowCircleTip),
            Arrow([-4, -2.5, 0], [2, -2.5, 0], tip_shape=ArrowCircleFilledTip),
            Arrow([-4, -3.5, 0], [2, -3.5, 0], tip_shape=StealthTip)
        ]

        small_arrows = (
            arrow.copy().scale(0.5, scale_tips=True).next_to(arrow, RIGHT) for arrow in big_arrows
        )

        labels = (
            Text(tip_names[i], font='monospace', font_size=20, color=BLUE).next_to(big_arrows[i], LEFT) for i in range(len(big_arrows))
        )

        self.add(*big_arrows, *small_arrows, *labels)
property base: Point3D

The base point of the arrow tip.

This is the point connecting to the arrow line.

Examples
>>> from manim import Arrow
>>> arrow = Arrow(np.array([0, 0, 0]), np.array([2, 0, 0]), buff=0)
>>> arrow.tip.base.round(2) + 0.  # add 0. to avoid negative 0 in output
array([1.65, 0.  , 0.  ])
property length: float

The length of the arrow tip.

Examples
>>> from manim import Arrow
>>> arrow = Arrow(np.array([0, 0, 0]), np.array([1, 2, 0]))
>>> round(arrow.tip.length, 3)
0.35
property tip_angle: float

The angle of the arrow tip.

Examples
>>> from manim import Arrow
>>> arrow = Arrow(np.array([0, 0, 0]), np.array([1, 1, 0]), buff=0)
>>> bool(round(arrow.tip.tip_angle, 5) == round(PI/4, 5))
True
property tip_point: Point3D

The tip point of the arrow tip.

Examples
>>> from manim import Arrow
>>> arrow = Arrow(np.array([0, 0, 0]), np.array([2, 0, 0]), buff=0)
>>> arrow.tip.tip_point.round(2) + 0.
array([2., 0., 0.])
property vector: Vector3D

The vector pointing from the base point to the tip point.

Examples
>>> from manim import Arrow
>>> arrow = Arrow(np.array([0, 0, 0]), np.array([2, 2, 0]), buff=0)
>>> arrow.tip.vector.round(2) + 0.
array([0.25, 0.25, 0.  ])

ArrowTriangleFilledTip

三角实心箭尖(默认样式),一般不直接实例化。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "RegularPolygram"; "RegularPolygram" -> "RegularPolygon"; "RegularPolygon" -> "Triangle"; "Triangle" -> "ArrowTip"; "ArrowTip" -> "ArrowTriangleTip"; "ArrowTriangleTip" -> "ArrowTriangleFilledTip"; }

参数

fill_opacity

1,float

stroke_width

0,float

API 文档

class manim.ArrowTriangleFilledTip(fill_opacity: float = 1, stroke_width: float = 0, **kwargs: Any)

基类:ArrowTriangleTip

Triangular arrow tip with filled tip.

This is the default arrow tip shape.

ArrowTriangleTip

空心三角箭尖样式类。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "RegularPolygram"; "RegularPolygram" -> "RegularPolygon"; "RegularPolygon" -> "Triangle"; "Triangle" -> "ArrowTip"; "ArrowTip" -> "ArrowTriangleTip"; }

参数

fill_opacity

0,float

stroke_width

3,float

length

0.35,float

width

0.35,float

start_angle

3.141592653589793,float

API 文档

class manim.ArrowTriangleTip(fill_opacity: float = 0, stroke_width: float = 3, length: float = 0.35, width: float = 0.35, start_angle: float = 3.141592653589793, **kwargs: Any)

基类:ArrowTip, Triangle

Triangular arrow tip.

BackgroundRectangle

自动包裹目标对象的背景色矩形:给文字图形加底色衬垫,防止与背景混淆。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "Polygon"; "Polygon" -> "Rectangle"; "Rectangle" -> "RoundedRectangle"; "RoundedRectangle" -> "SurroundingRectangle"; "SurroundingRectangle" -> "BackgroundRectangle"; }

参数

color

None

stroke_width

0,float

stroke_opacity

0,float

fill_opacity

0.75,float

buff

0

快速上手

bg = BackgroundRectangle(label, fill_opacity=0.7)

API 文档

class manim.BackgroundRectangle(*mobjects: Mobject, color: ManimColor | int | str | NDArray[int64] | tuple[int, int, int] | NDArray[float64] | tuple[float, float, float] | tuple[int, int, int, int] | tuple[float, float, float, float] | None = None, stroke_width: float = 0, stroke_opacity: float = 0, fill_opacity: float = 0.75, buff: float | tuple[float, float] = 0, **kwargs: Any)

基类:SurroundingRectangle

A background rectangle. Its default color is the background color of the scene.

Examples

class ExampleBackgroundRectangle(Scene):
    def construct(self):
        circle = Circle().shift(LEFT)
        circle.set_stroke(color=GREEN, width=20)
        triangle = Triangle().shift(2 * RIGHT)
        triangle.set_fill(PINK, opacity=0.5)
        backgroundRectangle1 = BackgroundRectangle(circle, color=WHITE, fill_opacity=0.15)
        backgroundRectangle2 = BackgroundRectangle(triangle, color=WHITE, fill_opacity=0.15)
        self.add(backgroundRectangle1)
        self.add(backgroundRectangle2)
        self.add(circle)
        self.add(triangle)
        self.play(Rotate(backgroundRectangle1, PI / 4))
        self.play(Rotate(backgroundRectangle2, PI / 2))
pointwise_become_partial(mobject: Mobject, a: Any, b: float) → Self

Given a 2nd VMobject vmobject, a lower bound a and an upper bound b, modify this VMobject's points to match the portion of the Bézier spline described by vmobject.points with the parameter t between a and b.

Parameters
vmobject

The VMobject that will serve as a model.

a

The lower bound for t.

b

The upper bound for t

Returns
VMobject

The VMobject itself, after the transformation.

Raises
TypeError

If vmobject is not an instance of VMobject.

Circle

圆:radius 或 diameter 指定大小,提供 from_three_points、point_at_angle、surround 等几何工厂方法。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; "Arc" -> "Circle"; }

参数

radius

None,float | None

color

ManimColor('#FC6255'),ParsableManimColor

快速上手

c = Circle(radius=2, color=BLUE)

API 文档

class manim.Circle(radius: float | None = None, color: ManimColor | int | str | NDArray[int64] | tuple[int, int, int] | NDArray[float64] | tuple[float, float, float] | tuple[int, int, int, int] | tuple[float, float, float, float] = ManimColor('#FC6255'), **kwargs: Any)

基类:Arc

A circle.

Parameters

color

The color of the shape.

kwargs

Additional arguments to be passed to Arc

Examples

class CircleExample(Scene):
    def construct(self):
        circle_1 = Circle(radius=1.0)
        circle_2 = Circle(radius=1.5, color=GREEN)
        circle_3 = Circle(radius=1.0, color=BLUE_B, fill_opacity=1)

        circle_group = Group(circle_1, circle_2, circle_3).arrange(buff=1)
        self.add(circle_group)
static from_three_points(p1: Point3DLike, p2: Point3DLike, p3: Point3DLike, **kwargs: Any) → Circle

Returns a circle passing through the specified three points.

Example
class CircleFromPointsExample(Scene):
    def construct(self):
        circle = Circle.from_three_points(LEFT, LEFT + UP, UP * 2, color=RED)
        dots = VGroup(
            Dot(LEFT),
            Dot(LEFT + UP),
            Dot(UP * 2),
        )
        self.add(NumberPlane(), circle, dots)
point_at_angle(angle: float) → Point3D

Returns the position of a point on the circle.

Parameters
angle

The angle of the point along the circle in radians.

Returns
numpy.ndarray

The location of the point along the circle's circumference.

Examples
class PointAtAngleExample(Scene):
    def construct(self):
        circle = Circle(radius=2.0)
        p1 = circle.point_at_angle(PI/2)
        p2 = circle.point_at_angle(270*DEGREES)

        s1 = Square(side_length=0.25).move_to(p1)
        s2 = Square(side_length=0.25).move_to(p2)
        self.add(circle, s1, s2)
surround(mobject: Mobject, dim_to_match: int = 0, stretch: bool = False, buffer_factor: float = 1.2) → Self

Modifies a circle so that it surrounds a given mobject.

Parameters
mobject

The mobject that the circle will be surrounding.

dim_to_match buffer_factor

Scales the circle with respect to the mobject. A buffer_factor < 1 makes the circle smaller than the mobject.

stretch

Stretches the circle to fit more tightly around the mobject. Note: Does not work with Line

Examples
class CircleSurround(Scene):
    def construct(self):
        triangle1 = Triangle()
        circle1 = Circle().surround(triangle1)
        group1 = Group(triangle1,circle1) # treat the two mobjects as one

        line2 = Line()
        circle2 = Circle().surround(line2, buffer_factor=2.0)
        group2 = Group(line2,circle2)

        # buffer_factor < 1, so the circle is smaller than the square
        square3 = Square()
        circle3 = Circle().surround(square3, buffer_factor=0.5)
        group3 = Group(square3, circle3)

        group = Group(group1, group2, group3).arrange(buff=1)
        self.add(group)

ConvexHull

一组点的凸包多边形:自动计算外轮廓,计算几何可视化。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "ConvexHull"; }

参数

API 文档

class manim.ConvexHull(*points: Point3DLike, tolerance: float = 1e-05, **kwargs: Any)

基类:Polygram

Constructs a convex hull for a set of points in no particular order.

Parameters

points

The points to consider.

tolerance

The tolerance used by quickhull.

kwargs

Forwarded to the parent constructor.

Examples

class ConvexHullExample(Scene):
    def construct(self):
        points = [
            [-2.35, -2.25, 0],
            [1.65, -2.25, 0],
            [2.65, -0.25, 0],
            [1.65, 1.75, 0],
            [-0.35, 2.75, 0],
            [-2.35, 0.75, 0],
            [-0.35, -1.25, 0],
            [0.65, -0.25, 0],
            [-1.35, 0.25, 0],
            [0.15, 0.75, 0]
        ]
        hull = ConvexHull(*points, color=BLUE)
        dots = VGroup(*[Dot(point) for point in points])
        self.add(hull)
        self.add(dots)

Cross

叉号(×)图形:stroke_width 和比例可调,标记错误或否定语义。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "VGroup"; "VGroup" -> "Cross"; }

参数

mobject

None,Mobject | None

stroke_color

ManimColor('#FC6255'),ParsableManimColor

stroke_width

6.0,float

scale_factor

1.0,float

快速上手

cross = Cross(mob)

API 文档

class manim.Cross(mobject: Mobject | None = None, stroke_color: ManimColor | int | str | NDArray[int64] | tuple[int, int, int] | NDArray[float64] | tuple[float, float, float] | tuple[int, int, int, int] | tuple[float, float, float, float] = ManimColor('#FC6255'), stroke_width: float = 6.0, scale_factor: float = 1.0, **kwargs: Any)

基类:VGroup

Creates a cross.

Parameters

mobject

The mobject linked to this instance. It fits the mobject when specified. Defaults to None.

stroke_color

Specifies the color of the cross lines. Defaults to RED.

stroke_width

Specifies the width of the cross lines. Defaults to 6.

scale_factor

Scales the cross to the provided units. Defaults to 1.

Examples

class ExampleCross(Scene):
    def construct(self):
        cross = Cross()
        self.add(cross)

CubicBezier

三次贝塞尔曲线:两个锚点 + 两个控制点,是矢量绘图的最小单元。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "CubicBezier"; }

参数

start_anchor

—,Point3DLike

start_handle

—,Point3DLike

end_handle

—,Point3DLike

end_anchor

—,Point3DLike

快速上手

b = CubicBezier(a1, h1, h2, a2)

API 文档

class manim.CubicBezier(start_anchor: Point3DLike, start_handle: Point3DLike, end_handle: Point3DLike, end_anchor: Point3DLike, **kwargs: Any)

基类:VMobject

A cubic Bézier curve.

Example

class BezierSplineExample(Scene):
    def construct(self):
        p1 = np.array([-3, 1, 0])
        p1b = p1 + [1, 0, 0]
        d1 = Dot(point=p1).set_color(BLUE)
        l1 = Line(p1, p1b)
        p2 = np.array([3, -1, 0])
        p2b = p2 - [1, 0, 0]
        d2 = Dot(point=p2).set_color(RED)
        l2 = Line(p2, p2b)
        bezier = CubicBezier(p1b, p1b + 3 * RIGHT, p2b - 3 * RIGHT, p2b)
        self.add(l1, d1, l2, d2, bezier)

CurvedArrow

弯曲的箭头:ArcBetweenPoints + 箭尖的组合体,流程图里绕过障碍的连线。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; "Arc" -> "ArcBetweenPoints"; "ArcBetweenPoints" -> "CurvedArrow"; }

参数

start_point

—,Point3DLike

end_point

—,Point3DLike

API 文档

class manim.CurvedArrow(start_point: Point3DLike, end_point: Point3DLike, **kwargs: Any)

基类:ArcBetweenPoints

CurvedDoubleArrow

两端都带箭尖的弯弧,双向关系专用。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; "Arc" -> "ArcBetweenPoints"; "ArcBetweenPoints" -> "CurvedArrow"; "CurvedArrow" -> "CurvedDoubleArrow"; }

参数

start_point

—,Point3DLike

end_point

—,Point3DLike

API 文档

class manim.CurvedDoubleArrow(start_point: Point3DLike, end_point: Point3DLike, **kwargs: Any)

基类:CurvedArrow

Cutout

带镂空的多边形:外部轮廓减内部孔洞,fill 模式下孔洞透明。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Cutout"; }

参数

快速上手

c = Cutout(square, circle)

API 文档

class manim.Cutout(main_shape: VMobject, *mobjects: VMobject, **kwargs: Any)

基类:VMobject

A shape with smaller cutouts.

Parameters

main_shape

The primary shape from which cutouts are made.

mobjects

The smaller shapes which are to be cut out of the main_shape.

kwargs

Further keyword arguments that are passed to the constructor of VMobject.

警告

Technically, this class behaves similar to a symmetric difference: if parts of the mobjects are not located within the main_shape, these parts will be added to the resulting VMobject.

Examples

class CutoutExample(Scene):
    def construct(self):
        s1 = Square().scale(2.5)
        s2 = Triangle().shift(DOWN + RIGHT).scale(0.5)
        s3 = Square().shift(UP + RIGHT).scale(0.5)
        s4 = RegularPolygon(5).shift(DOWN + LEFT).scale(0.5)
        s5 = RegularPolygon(6).shift(UP + LEFT).scale(0.5)
        c = Cutout(s1, s2, s3, s4, s5, fill_opacity=1, color=BLUE, stroke_color=RED)
        self.play(Write(c), run_time=4)
        self.wait()

DashedLine

虚线直线:DashedVMobject 的直线便捷版,辅助线首选。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Line"; "Line" -> "DashedLine"; }

参数

dash_length

0.05,float

dashed_ratio

0.5,float

快速上手

d = DashedLine(LEFT, RIGHT)

API 文档

class manim.DashedLine(*args: Any, dash_length: float = 0.05, dashed_ratio: float = 0.5, **kwargs: Any)

基类:Line

A dashed Line.

Parameters

args

Arguments to be passed to Line

dash_length

The length of each individual dash of the line.

dashed_ratio

The ratio of dash space to empty space. Range of 0-1.

kwargs

Additional arguments to be passed to Line

Examples

class DashedLineExample(Scene):
    def construct(self):
        # dash_length increased
        dashed_1 = DashedLine(config.left_side, config.right_side, dash_length=2.0).shift(UP*2)
        # normal
        dashed_2 = DashedLine(config.left_side, config.right_side)
        # dashed_ratio decreased
        dashed_3 = DashedLine(config.left_side, config.right_side, dashed_ratio=0.1).shift(DOWN*2)
        self.add(dashed_1, dashed_2, dashed_3)
get_end() → Point3D

Returns the end point of the line.

Examples
>>> DashedLine().get_end()
array([1., 0., 0.])
get_first_handle() → Point3D

Returns the point of the first handle.

Examples
>>> DashedLine().get_first_handle()
array([-0.98333333,  0.        ,  0.        ])
get_last_handle() → Point3D

Returns the point of the last handle.

Examples
>>> DashedLine().get_last_handle()
array([0.98333333, 0.        , 0.        ])
get_start() → Point3D

Returns the start point of the line.

Examples
>>> DashedLine().get_start()
array([-1.,  0.,  0.])

Difference

布尔差集:从主体图形中挖掉重叠部分,属于 VMobject 布尔运算家族。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Difference"; }

参数

subject

—,VMobject

clip

—,VMobject

快速上手

diff = Difference(square, circle)

API 文档

class manim.Difference(subject: VMobject, clip: VMobject, **kwargs: Any)

基类:_BooleanOps

Subtracts one VMobject from another one.

Parameters

subject

The 1st VMobject.

clip

The 2nd VMobject

Example

class DifferenceExample(Scene):
    def construct(self):
        sq = Square(color=RED, fill_opacity=1)
        sq.move_to([-2, 0, 0])
        cr = Circle(color=BLUE, fill_opacity=1)
        cr.move_to([-1.3, 0.7, 0])
        un = Difference(sq, cr, color=GREEN, fill_opacity=1)
        un.move_to([1.5, 0, 0])
        self.add(sq, cr, un)

Dot

小圆点:radius 很小且 fill 为主,标记坐标、描点画图的基本单元。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; "Arc" -> "Circle"; "Circle" -> "Dot"; }

参数

point

array([0., 0., 0.]),Point3DLike

radius

0.08,float

stroke_width

0,float

fill_opacity

1.0,float

color

ManimColor('#FFFFFF'),ParsableManimColor

快速上手

dot = Dot(point, color=RED)

API 文档

class manim.Dot(point: Point3DLike = array([0., 0., 0.]), radius: float = 0.08, stroke_width: float = 0, fill_opacity: float = 1.0, color: ParsableManimColor = ManimColor('#FFFFFF'), **kwargs: Any)

基类:Circle

A circle with a very small radius.

Parameters

point

The location of the dot.

radius

The radius of the dot.

stroke_width

The thickness of the outline of the dot.

fill_opacity

The opacity of the dot's fill_colour

color

The color of the dot.

kwargs

Additional arguments to be passed to Circle

Examples

class DotExample(Scene):
    def construct(self):
        dot1 = Dot(point=LEFT, radius=0.08)
        dot2 = Dot(point=ORIGIN)
        dot3 = Dot(point=RIGHT)
        self.add(dot1,dot2,dot3)

DoubleArrow

两端都有箭头的直线,表示双向映射或区间。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Line"; "Line" -> "Arrow"; "Arrow" -> "DoubleArrow"; }

快速上手

d = DoubleArrow(LEFT, RIGHT)

API 文档

class manim.DoubleArrow(*args: Any, **kwargs: Any)

基类:Arrow

An arrow with tips on both ends.

Parameters

args

Arguments to be passed to Arrow

kwargs

Additional arguments to be passed to Arrow

参见

ArrowTip CurvedDoubleArrow

Examples

from manim.mobject.geometry.tips import ArrowCircleFilledTip
class DoubleArrowExample(Scene):
    def construct(self):
        circle = Circle(radius=2.0)
        d_arrow = DoubleArrow(start=circle.get_left(), end=circle.get_right())
        d_arrow_2 = DoubleArrow(tip_shape_end=ArrowCircleFilledTip, tip_shape_start=ArrowCircleFilledTip)
        group = Group(Group(circle, d_arrow), d_arrow_2).arrange(UP, buff=1)
        self.add(group)
class DoubleArrowExample2(Scene):
    def construct(self):
        box = Square()
        p1 = box.get_left()
        p2 = box.get_right()
        d1 = DoubleArrow(p1, p2, buff=0)
        d2 = DoubleArrow(p1, p2, buff=0, tip_length=0.2, color=YELLOW)
        d3 = DoubleArrow(p1, p2, buff=0, tip_length=0.4, color=BLUE)
        Group(d1, d2, d3).arrange(DOWN)
        self.add(box, d1, d2, d3)

Elbow

直角弯头线:两条垂直短线段,管道图、直角坐标标记用。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Elbow"; }

参数

width

0.2,float

angle

0,float

API 文档

class manim.Elbow(width: float = 0.2, angle: float = 0, **kwargs: Any)

基类:VMobject

Two lines that create a right angle about each other: L-shape.

Parameters

width

The length of the elbow's sides.

angle

The rotation of the elbow.

kwargs

Additional arguments to be passed to VMobject

参见

RightAngle

Examples

class ElbowExample(Scene):
    def construct(self):
        elbow_1 = Elbow()
        elbow_2 = Elbow(width=2.0)
        elbow_3 = Elbow(width=2.0, angle=5*PI/4)

        elbow_group = Group(elbow_1, elbow_2, elbow_3).arrange(buff=1)
        self.add(elbow_group)

Ellipse

椭圆:width/height 分别指定两轴,圆形的长轴版。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; "Arc" -> "Circle"; "Circle" -> "Ellipse"; }

参数

width

2,float

height

1,float

快速上手

e = Ellipse(width=4, height=2)

API 文档

class manim.Ellipse(width: float = 2, height: float = 1, **kwargs: Any)

基类:Circle

A circular shape; oval, circle.

Parameters

width

The horizontal width of the ellipse.

height

The vertical height of the ellipse.

kwargs

Additional arguments to be passed to Circle.

Examples

class EllipseExample(Scene):
    def construct(self):
        ellipse_1 = Ellipse(width=2.0, height=4.0, color=BLUE_B)
        ellipse_2 = Ellipse(width=4.0, height=1.0, color=BLUE_D)
        ellipse_group = Group(ellipse_1,ellipse_2).arrange(buff=1)
        self.add(ellipse_group)

Exclusion

布尔异或:只保留两个图形不重叠的部分。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Exclusion"; }

参数

subject

—,VMobject

clip

—,VMobject

API 文档

class manim.Exclusion(subject: VMobject, clip: VMobject, **kwargs: Any)

基类:_BooleanOps

Find the XOR between two VMobject. This creates a new VMobject consisting of the region covered by exactly one of them.

Parameters

subject

The 1st VMobject.

clip

The 2nd VMobject

Example

class IntersectionExample(Scene):
    def construct(self):
        sq = Square(color=RED, fill_opacity=1)
        sq.move_to([-2, 0, 0])
        cr = Circle(color=BLUE, fill_opacity=1)
        cr.move_to([-1.3, 0.7, 0])
        un = Exclusion(sq, cr, color=GREEN, fill_opacity=1)
        un.move_to([1.5, 0.4, 0])
        self.add(sq, cr, un)

Intersection

布尔交集:只保留两个图形重叠的区域。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Intersection"; }

快速上手

i = Intersection(square, circle)

API 文档

class manim.Intersection(*vmobjects: VMobject, **kwargs: Any)

基类:_BooleanOps

Find the intersection of two VMobject s. This keeps the parts covered by both VMobject s.

Parameters

vmobjects

The VMobject to find the intersection.

Raises

ValueError

If less the 2 VMobject are passed.

Example

class IntersectionExample(Scene):
    def construct(self):
        sq = Square(color=RED, fill_opacity=1)
        sq.move_to([-2, 0, 0])
        cr = Circle(color=BLUE, fill_opacity=1)
        cr.move_to([-1.3, 0.7, 0])
        un = Intersection(sq, cr, color=GREEN, fill_opacity=1)
        un.move_to([1.5, 0, 0])
        self.add(sq, cr, un)

Label

几何图形上的标签:自带背景框的小文本,跟随目标位置摆放。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "VGroup"; "VGroup" -> "Label"; }

参数

label

—,str | ManimTextLabel

label_config

None,dict[str, Any] | None

box_config

None,dict[str, Any] | None

frame_config

None,dict[str, Any] | None

API 文档

class manim.Label(label: str | ManimTextLabel, label_config: dict[str, Any] | None = None, box_config: dict[str, Any] | None = None, frame_config: dict[str, Any] | None = None, **kwargs: Any)

基类:VGroup

A Label consisting of text surrounded by a frame.

Parameters

label

Label that will be displayed.

label_config

A dictionary containing the configuration for the label. This is only applied if label is of type str.

box_config

A dictionary containing the configuration for the background box.

frame_config

A dictionary containing the configuration for the frame.

Examples

class LabelExample(Scene):
    def construct(self):
        label = Label(
            label=Text('Label Text', font='sans-serif'),
            box_config = {
                "color" : BLUE,
                "fill_opacity" : 0.75
            }
        )
        label.scale(3)
        self.add(label)

LabeledArrow

带文字标签的箭头:label 自动置于箭身中点,省去手动对位。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Line"; "Line" -> "Arrow"; "Arrow" -> "LabeledLine"; "LabeledLine" -> "LabeledArrow"; }

API 文档

class manim.LabeledArrow(*args: Any, **kwargs: Any)

基类:LabeledLine, Arrow

Constructs an arrow containing a label box somewhere along its length. This class inherits its label properties from LabeledLine, so the main parameters controlling it are the same.

Parameters

label

Label that will be displayed on the Arrow.

label_position

A ratio in the range [0-1] to indicate the position of the label with respect to the length of the line. Default value is 0.5.

label_config

A dictionary containing the configuration for the label. This is only applied if label is of type str.

box_config

A dictionary containing the configuration for the background box.

frame_config

A dictionary containing the configuration for the frame.

参见

LabeledLine

Examples

class LabeledArrowExample(Scene):
    def construct(self):
        l_arrow = LabeledArrow("0.5", start=LEFT*3, end=RIGHT*3 + UP*2, label_position=0.5)

        self.add(l_arrow)

LabeledDot

带文字标签的圆点:标签居中于点内,图论顶点标注专用。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; "Arc" -> "Circle"; "Circle" -> "Dot"; "Dot" -> "LabeledDot"; }

参数

label

—

radius

None,float | None

buff

0.1,float

API 文档

class manim.LabeledDot(label: str | SingleStringMathTex | Text | Tex, radius: float | None = None, buff: float = 0.1, **kwargs: Any)

基类:Dot

A Dot containing a label in its center.

Parameters

label

The label of the Dot. This is rendered as MathTex by default (i.e., when passing a str), but other classes representing rendered strings like Text or Tex can be passed as well.

radius

The radius of the Dot. If provided, the buff is ignored. If None (the default), the radius is calculated based on the size of the label and the buff.

Examples

class SeveralLabeledDots(Scene):
    def construct(self):
        sq = Square(fill_color=RED, fill_opacity=1)
        self.add(sq)
        dot1 = LabeledDot(Tex("42", color=RED))
        dot2 = LabeledDot(MathTex("a", color=GREEN))
        dot3 = LabeledDot(Text("ii", color=BLUE))
        dot4 = LabeledDot("3")
        dot1.next_to(sq, UL)
        dot2.next_to(sq, UR)
        dot3.next_to(sq, DL)
        dot4.next_to(sq, DR)
        self.add(dot1, dot2, dot3, dot4)

LabeledLine

带标签的直线:标签自动放在线段中点。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Line"; "Line" -> "LabeledLine"; }

参数

label

—,str | ManimTextLabel

label_position

0.5,float

label_config

None,dict[str, Any] | None

box_config

None,dict[str, Any] | None

frame_config

None,dict[str, Any] | None

API 文档

class manim.LabeledLine(label: str | ManimTextLabel, label_position: float = 0.5, label_config: dict[str, Any] | None = None, box_config: dict[str, Any] | None = None, frame_config: dict[str, Any] | None = None, *args: Any, **kwargs: Any)

基类:Line

Constructs a line containing a label box somewhere along its length.

Parameters

label

Label that will be displayed on the line.

label_position

A ratio in the range [0-1] to indicate the position of the label with respect to the length of the line. Default value is 0.5.

label_config

A dictionary containing the configuration for the label. This is only applied if label is of type str.

box_config

A dictionary containing the configuration for the background box.

frame_config

A dictionary containing the configuration for the frame.

参见

LabeledArrow

Examples

class LabeledLineExample(Scene):
    def construct(self):
        line = LabeledLine(
            label          = '0.5',
            label_position = 0.8,
            label_config = {
                "font_size" : 20
            },
            start=LEFT+DOWN,
            end=RIGHT+UP)

        line.set_length(line.get_length() * 2)
        self.add(line)

LabeledPolygram

带顶点标签的折线/多边形:每个顶点自动编号。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "LabeledPolygram"; }

参数

label

—,str | ManimTextLabel

precision

0.01,float

label_config

None,dict[str, Any] | None

box_config

None,dict[str, Any] | None

frame_config

None,dict[str, Any] | None

API 文档

class manim.LabeledPolygram(*vertex_groups: Point3DLike_Array, label: str | ManimTextLabel, precision: float = 0.01, label_config: dict[str, Any] | None = None, box_config: dict[str, Any] | None = None, frame_config: dict[str, Any] | None = None, **kwargs: Any)

基类:Polygram

Constructs a polygram containing a label box at its pole of inaccessibility.

Parameters

vertex_groups

Vertices passed to the Polygram constructor.

label

Label that will be displayed on the Polygram.

precision

The precision used by the PolyLabel algorithm.

label_config

A dictionary containing the configuration for the label. This is only applied if label is of type str.

box_config

A dictionary containing the configuration for the background box.

frame_config

A dictionary containing the configuration for the frame.

备注

The PolyLabel Algorithm expects each vertex group to form a closed ring. If the input is open, LabeledPolygram will attempt to close it. This may cause the polygon to intersect itself leading to unexpected results.

小技巧

Make sure the precision corresponds to the scale of your inputs! For instance, if the bounding box of your polygon stretches from 0 to 10,000, a precision of 1.0 or 10.0 should be sufficient.

Examples

class LabeledPolygramExample(Scene):
    def construct(self):
        # Define Rings
        ring1 = [
            [-3.8, -2.4, 0], [-2.4, -2.5, 0], [-1.3, -1.6, 0], [-0.2, -1.7, 0],
            [1.7, -2.5, 0], [2.9, -2.6, 0], [3.5, -1.5, 0], [4.9, -1.4, 0],
            [4.5, 0.2, 0], [4.7, 1.6, 0], [3.5, 2.4, 0], [1.1, 2.5, 0],
            [-0.1, 0.9, 0], [-1.2, 0.5, 0], [-1.6, 0.7, 0], [-1.4, 1.9, 0],
            [-2.6, 2.6, 0], [-4.4, 1.2, 0], [-4.9, -0.8, 0], [-3.8, -2.4, 0]
        ]
        ring2 = [
            [0.2, -1.2, 0], [0.9, -1.2, 0], [1.4, -2.0, 0], [2.1, -1.6, 0],
            [2.2, -0.5, 0], [1.4, 0.0, 0], [0.4, -0.2, 0], [0.2, -1.2, 0]
        ]
        ring3 = [[-2.7, 1.4, 0], [-2.3, 1.7, 0], [-2.8, 1.9, 0], [-2.7, 1.4, 0]]

        # Create Polygons (for reference)
        p1 = Polygon(*ring1, fill_opacity=0.75)
        p2 = Polygon(*ring2, fill_color=BLACK, fill_opacity=1)
        p3 = Polygon(*ring3, fill_color=BLACK, fill_opacity=1)

        # Create Labeled Polygram
        polygram = LabeledPolygram(
            *[ring1, ring2, ring3],
            label=Text('Pole', font='sans-serif'),
            precision=0.01,
        )

        # Display Circle (for reference)
        circle = Circle(radius=polygram.radius, color=WHITE).move_to(polygram.pole)

        self.add(p1, p2, p3)
        self.add(polygram)
        self.add(circle)
import requests
import json

class LabeledCountryExample(Scene):
    def construct(self):
        # Fetch JSON data and process arcs
        data = requests.get('https://cdn.jsdelivr.net/npm/us-atlas@3/nation-10m.json').json()
        arcs, transform = data['arcs'], data['transform']
        sarcs = [np.cumsum(arc, axis=0) * transform['scale'] + transform['translate'] for arc in arcs]
        ssarcs = sorted(sarcs, key=len, reverse=True)[:1]

        # Compute Bounding Box
        points = np.concatenate(ssarcs)
        mins, maxs = np.min(points, axis=0), np.max(points, axis=0)

        # Build Axes
        ax = Axes(
            x_range=[mins[0], maxs[0], maxs[0] - mins[0]], x_length=10,
            y_range=[mins[1], maxs[1], maxs[1] - mins[1]], y_length=7,
            tips=False
        )

        # Adjust Coordinates
        array = [[ax.c2p(*point) for point in sarc] for sarc in ssarcs]

        # Add Polygram
        polygram = LabeledPolygram(
            *array,
            label=Text('USA', font='sans-serif'),
            precision=0.01,
            fill_color=BLUE,
            stroke_width=0,
            fill_opacity=0.75
        )

        # Display Circle (for reference)
        circle = Circle(radius=polygram.radius, color=WHITE).move_to(polygram.pole)

        self.add(ax)
        self.add(polygram)
        self.add(circle)

Line

两点之间的直线:buff 让端点留白不压对象,put_start_and_end_on 可动画化,是构图的骨架。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Line"; }

参数

start

array([-1., 0., 0.]),Point3DLike | Mobject

end

array([1., 0., 0.]),Point3DLike | Mobject

buff

0,float

path_arc

0,float

快速上手

line = Line(ORIGIN, RIGHT * 3)

API 文档

class manim.Line(start: Point3DLike | Mobject = array([-1., 0., 0.]), end: Point3DLike | Mobject = array([1., 0., 0.]), buff: float = 0, path_arc: float = 0, **kwargs: Any)

基类:TipableVMobject

A straight or curved line segment between two points or mobjects.

Parameters

start

The starting point or Mobject of the line.

end

The ending point or Mobject of the line.

buff

The distance to shorten the line from both ends.

path_arc

If nonzero, the line will be curved into an arc with this angle (in radians).

kwargs

Additional arguments to be passed to TipableVMobject

Examples

class LineExample(Scene):
    def construct(self):
        line1 = Line(LEFT*2, RIGHT*2)
        line2 = Line(LEFT*2, RIGHT*2, buff=0.5)
        line3 = Line(LEFT*2, RIGHT*2, path_arc=PI/2)
        grp = VGroup(line1,line2,line3).arrange(DOWN, buff=2)
        self.add(grp)
generate_points() → Self

Initializes points and therefore the shape.

Gets called upon creation. This is an empty method that can be implemented by subclasses.

get_projection(point: Point3DLike) → Point3D

Returns the projection of a point onto a line.

Parameters
point

The point to which the line is projected.

put_start_and_end_on(start: Point3DLike, end: Point3DLike) → Self

Sets starts and end coordinates of a line.

Examples
class LineExample(Scene):
    def construct(self):
        d = VGroup()
        for i in range(0,10):
            d.add(Dot())
        d.arrange_in_grid(buff=1)
        self.add(d)
        l= Line(d[0], d[1])
        self.add(l)
        self.wait()
        l.put_start_and_end_on(d[1].get_center(), d[2].get_center())
        self.wait()
        l.put_start_and_end_on(d[4].get_center(), d[7].get_center())
        self.wait()
set_points_by_ends(start: Point3DLike | Mobject, end: Point3DLike | Mobject, buff: float = 0, path_arc: float = 0) → Self

Sets the points of the line based on its start and end points. Unlike put_start_and_end_on(), this method respects self.buff and Mobject bounding boxes.

Parameters
start

The start point or Mobject of the line.

end

The end point or Mobject of the line.

buff

The empty space between the start and end of the line, by default 0.

path_arc

The angle of a circle spanned by this arc, by default 0 which is a straight line.

Polygon

多边形:顶点列表连线闭合,一切直边图形(三角形、矩形……)的基类。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "Polygon"; }

快速上手

p = Polygon(ORIGIN, RIGHT, UP)

API 文档

class manim.Polygon(*vertices: Point3DLike, **kwargs: Any)

基类:Polygram

A shape consisting of one closed loop of vertices.

Parameters

vertices

The vertices of the Polygon.

kwargs

Forwarded to the parent constructor.

Examples

class PolygonExample(Scene):
    def construct(self):
        isosceles = Polygon([-5, 1.5, 0], [-2, 1.5, 0], [-3.5, -2, 0])
        position_list = [
            [4, 1, 0],  # middle right
            [4, -2.5, 0],  # bottom right
            [0, -2.5, 0],  # bottom left
            [0, 3, 0],  # top left
            [2, 1, 0],  # middle
            [4, 3, 0],  # top right
        ]
        square_and_triangles = Polygon(*position_list, color=PURPLE_B)
        self.add(isosceles, square_and_triangles)

Polygram

折线组:可以含多个不闭合顶点组(组 = 一条折线),比 Polygon 更自由的连点工具。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; }

参数

API 文档

class manim.Polygram(*vertex_groups: Point3DLike_Array, color: ParsableManimColor = ManimColor('#58C4DD'), **kwargs: Any)

基类:VMobject

A generalized Polygon, allowing for disconnected sets of edges.

Parameters

vertex_groups

The groups of vertices making up the 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 Polygram.

kwargs

Forwarded to the parent constructor.

Examples

import numpy as np

class PolygramExample(Scene):
    def construct(self):
        hexagram = Polygram(
            [[0, 2, 0], [-np.sqrt(3), -1, 0], [np.sqrt(3), -1, 0]],
            [[-np.sqrt(3), 1, 0], [0, -2, 0], [np.sqrt(3), 1, 0]],
        )
        self.add(hexagram)

        dot = Dot()
        self.play(MoveAlongPath(dot, hexagram), run_time=5, rate_func=linear)
        self.remove(dot)
        self.wait()
get_vertex_groups() → list[Point3D_Array]

Gets the vertex groups of the Polygram.

Returns
list[Point3D_Array]

The list of vertex groups of the Polygram.

Examples
>>> poly = Polygram([ORIGIN, RIGHT, UP, LEFT + UP], [LEFT, LEFT + UP, 2 * LEFT])
>>> groups = poly.get_vertex_groups()
>>> len(groups)
2
>>> groups[0]
array([[ 0.,  0.,  0.],
       [ 1.,  0.,  0.],
       [ 0.,  1.,  0.],
       [-1.,  1.,  0.]])
>>> groups[1]
array([[-1.,  0.,  0.],
       [-1.,  1.,  0.],
       [-2.,  0.,  0.]])
get_vertices() → Point3D_Array

Gets the vertices of the Polygram.

Returns
numpy.ndarray

The vertices of the Polygram.

Examples
>>> sq = Square()
>>> sq.get_vertices()
array([[ 1.,  1.,  0.],
       [-1.,  1.,  0.],
       [-1., -1.,  0.],
       [ 1., -1.,  0.]])
round_corners(radius: float | list[float] = 0.5, evenly_distribute_anchors: bool = False, components_per_rounded_corner: int = 2) → Self

Rounds off the corners of the Polygram.

Parameters
radius

The curvature of the corners of the Polygram.

evenly_distribute_anchors

Break long line segments into proportionally-sized segments.

components_per_rounded_corner

The number of points used to represent the rounded corner curve.

参见

RoundedRectangle

备注

If radius is supplied as a single value, then the same radius will be applied to all corners. If radius is a list, then the individual values will be applied sequentially, with the first corner receiving radius[0], the second corner receiving radius[1], etc. The radius list will be repeated as necessary.

The components_per_rounded_corner value is provided so that the fidelity of the rounded corner may be fine-tuned as needed. 2 is an appropriate value for most shapes, however a larger value may be need if the rounded corner is particularly large. 2 is the minimum number allowed, representing the start and end of the curve. 3 will result in a start, middle, and end point, meaning 2 curves will be generated.

The option to evenly_distribute_anchors is provided so that the line segments (the part part of each line remaining after rounding off the corners) can be subdivided to a density similar to that of the average density of the rounded corners. This may be desirable in situations in which an even distribution of curves is desired for use in later transformation animations. Be aware, though, that enabling this option can result in an an object containing significantly more points than the original, especially when the rounded corner curves are small.

Examples
class PolygramRoundCorners(Scene):
    def construct(self):
        star = Star(outer_radius=2)

        shapes = VGroup(star)
        shapes.add(star.copy().round_corners(radius=0.1))
        shapes.add(star.copy().round_corners(radius=0.25))

        shapes.arrange(RIGHT)
        self.add(shapes)

Rectangle

矩形:width/height 与角半径可调,包围、对齐、底衬的主力图形。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "Polygon"; "Polygon" -> "Rectangle"; }

参数

color

ManimColor('#FFFFFF'),ParsableManimColor

height

2.0,float

width

4.0,float

grid_xstep

None,float | None

grid_ystep

None,float | None

mark_paths_closed

True,bool

close_new_points

True,bool

快速上手

r = Rectangle(width=4, height=2)

API 文档

class manim.Rectangle(color: ManimColor | int | str | NDArray[int64] | tuple[int, int, int] | NDArray[float64] | tuple[float, float, float] | tuple[int, int, int, int] | tuple[float, float, float, float] = ManimColor('#FFFFFF'), height: float = 2.0, width: float = 4.0, grid_xstep: float | None = None, grid_ystep: float | None = None, mark_paths_closed: bool = True, close_new_points: bool = True, **kwargs: Any)

基类:Polygon

A quadrilateral with two sets of parallel sides.

Parameters

color

The color of the rectangle.

height

The vertical height of the rectangle.

width

The horizontal width of the rectangle.

grid_xstep

Space between vertical grid lines.

grid_ystep

Space between horizontal grid lines.

mark_paths_closed

No purpose.

close_new_points

No purpose.

kwargs

Additional arguments to be passed to Polygon

Examples

class RectangleExample(Scene):
    def construct(self):
        rect1 = Rectangle(width=4.0, height=2.0, grid_xstep=1.0, grid_ystep=0.5)
        rect2 = Rectangle(width=1.0, height=4.0)
        rect3 = Rectangle(width=2.0, height=2.0, grid_xstep=1.0, grid_ystep=1.0)
        rect3.grid_lines.set_stroke(width=1)

        rects = Group(rect1, rect2, rect3).arrange(buff=1)
        self.add(rects)

RegularPolygon

正多边形:n 指定边数,内切圆半径可调。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "RegularPolygram"; "RegularPolygram" -> "RegularPolygon"; }

参数

快速上手

hexagon = RegularPolygon(n=6)

API 文档

class manim.RegularPolygon(n: int = 6, **kwargs: Any)

基类:RegularPolygram

An n-sided regular Polygon.

Parameters

n

The number of sides of the RegularPolygon.

kwargs

Forwarded to the parent constructor.

Examples

class RegularPolygonExample(Scene):
    def construct(self):
        poly_1 = RegularPolygon(n=6)
        poly_2 = RegularPolygon(n=6, start_angle=30*DEGREES, color=GREEN)
        poly_3 = RegularPolygon(n=10, color=RED)

        poly_group = Group(poly_1, poly_2, poly_3).scale(1.5).arrange(buff=1)
        self.add(poly_group)

RegularPolygram

正多角星:n 顶点按密度跳着连线(如五角星 density=2)。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "RegularPolygram"; }

参数

num_vertices

—,int

density

2,int

radius

1,float

start_angle

None,float | None

API 文档

class manim.RegularPolygram(num_vertices: int, *, density: int = 2, radius: float = 1, start_angle: float | None = None, **kwargs: Any)

基类:Polygram

A Polygram with regularly spaced vertices.

Parameters

num_vertices

The number of vertices.

density

The density of the RegularPolygram.

Can be thought of as how many vertices to hop to draw a line between them. Every density-th vertex is connected.

radius

The radius of the circle that the vertices are placed on.

start_angle

The angle the vertices start at; the rotation of the RegularPolygram.

kwargs

Forwarded to the parent constructor.

Examples

class RegularPolygramExample(Scene):
    def construct(self):
        pentagram = RegularPolygram(5, radius=2)
        self.add(pentagram)

RightAngle

直角标记:两条线垂直时的小方框角标,几何证明标配。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Angle"; "Angle" -> "RightAngle"; }

参数

line1

—,Line

line2

—,Line

length

None,float | None

快速上手

ra = RightAngle(line1, line2, length=0.3)

API 文档

class manim.RightAngle(line1: Line, line2: Line, length: float | None = None, **kwargs: Any)

基类:Angle

An elbow-type mobject representing a right angle between two lines.

Parameters

line1

The first line.

line2

The second line.

length

The length of the arms.

**kwargs

Further keyword arguments that are passed to the constructor of Angle.

Examples

class RightAngleExample(Scene):
    def construct(self):
        line1 = Line( LEFT, RIGHT )
        line2 = Line( DOWN, UP )
        rightangles = [
            RightAngle(line1, line2),
            RightAngle(line1, line2, length=0.4, quadrant=(1,-1)),
            RightAngle(line1, line2, length=0.5, quadrant=(-1,1), stroke_width=8),
            RightAngle(line1, line2, length=0.7, quadrant=(-1,-1), color=RED),
        ]
        plots = VGroup()
        for rightangle in rightangles:
            plot=VGroup(line1.copy(),line2.copy(), rightangle)
            plots.add(plot)
        plots.arrange(buff=1.5)
        self.add(plots)

RoundedRectangle

圆角矩形:corner_radius 控制圆角,卡片式 UI 元素的首选。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "Polygon"; "Polygon" -> "Rectangle"; "Rectangle" -> "RoundedRectangle"; }

参数

快速上手

card = RoundedRectangle(corner_radius=0.2, width=4, height=2)

API 文档

class manim.RoundedRectangle(corner_radius: float | list[float] = 0.5, **kwargs: Any)

基类:Rectangle

A rectangle with rounded corners.

Parameters

corner_radius

The curvature of the corners of the rectangle.

kwargs

Additional arguments to be passed to Rectangle

Examples

class RoundedRectangleExample(Scene):
    def construct(self):
        rect_1 = RoundedRectangle(corner_radius=0.5)
        rect_2 = RoundedRectangle(corner_radius=1.5, height=4.0, width=4.0)

        rect_group = Group(rect_1, rect_2).arrange(buff=1)
        self.add(rect_group)

Sector

扇形:圆 + 张角,饼图的组成单元。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; "Arc" -> "AnnularSector"; "AnnularSector" -> "Sector"; }

参数

快速上手

s = Sector(angle=PI/3)

API 文档

class manim.Sector(radius: float = 1, **kwargs: Any)

基类:AnnularSector

A sector of a circle.

Examples

class ExampleSector(Scene):
    def construct(self):
        sector = Sector(radius=2)
        sector2 = Sector(radius=2.5, angle=60*DEGREES).move_to([-3, 0, 0])
        sector.set_color(RED)
        sector2.set_color(PINK)
        self.add(sector, sector2)

Square

正方形:Rectangle 的等边便捷版,边长用 side_length。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "Polygon"; "Polygon" -> "Rectangle"; "Rectangle" -> "Square"; }

参数

快速上手

sq = Square(side_length=2)

API 文档

class manim.Square(side_length: float = 2.0, **kwargs: Any)

基类:Rectangle

A rectangle with equal side lengths.

Parameters

side_length

The length of the sides of the square.

kwargs

Additional arguments to be passed to Rectangle.

Examples

class SquareExample(Scene):
    def construct(self):
        square_1 = Square(side_length=2.0).shift(DOWN)
        square_2 = Square(side_length=1.0).next_to(square_1, direction=UP)
        square_3 = Square(side_length=0.5).next_to(square_2, direction=UP)
        self.add(square_1, square_2, square_3)

Star

五角星样式的正多角星:n 与密度决定角数,外内半径比决定胖瘦。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "Polygon"; "Polygon" -> "Star"; }

参数

n

5,int

outer_radius

1,float

inner_radius

None,float | None

density

2,int

start_angle

1.5707963267948966,float | None

快速上手

star = Star(n=5, fill_color=YELLOW)

API 文档

class manim.Star(n: int = 5, *, outer_radius: float = 1, inner_radius: float | None = None, density: int = 2, start_angle: float | None = 1.5707963267948966, **kwargs: Any)

基类:Polygon

A regular polygram without the intersecting lines.

Parameters

n

How many points on the Star.

outer_radius

The radius of the circle that the outer vertices are placed on.

inner_radius

The radius of the circle that the inner vertices are placed on.

If unspecified, the inner radius will be calculated such that the edges of the Star perfectly follow the edges of its RegularPolygram counterpart.

density

The density of the Star. Only used if inner_radius is unspecified.

See RegularPolygram for more information.

start_angle

The angle the vertices start at; the rotation of the Star.

kwargs

Forwardeds to the parent constructor.

Raises

ValueError

If inner_radius is unspecified and density is not in the range [1, n/2).

Examples

class StarExample(Scene):
    def construct(self):
        pentagram = RegularPolygram(5, radius=2)
        star = Star(outer_radius=2, color=RED)

        self.add(pentagram)
        self.play(Create(star), run_time=3)
        self.play(FadeOut(star), run_time=2)
class DifferentDensitiesExample(Scene):
    def construct(self):
        density_2 = Star(7, outer_radius=2, density=2, color=RED)
        density_3 = Star(7, outer_radius=2, density=3, color=PURPLE)

        self.add(VGroup(density_2, density_3).arrange(RIGHT))

StealthTip

隐形战斗机风格的箭尖(默认箭尖),一般不直接实例化。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "ArrowTip"; "ArrowTip" -> "StealthTip"; }

参数

fill_opacity

1,float

stroke_width

3,float

length

0.175,float

start_angle

3.141592653589793,float

API 文档

class manim.StealthTip(fill_opacity: float = 1, stroke_width: float = 3, length: float = 0.175, start_angle: float = 3.141592653589793, **kwargs: Any)

基类:ArrowTip

'Stealth' fighter / kite arrow shape.

Naming is inspired by the corresponding TikZ arrow shape.

property length: float

The length of the arrow tip.

In this case, the length is computed as the height of the triangle encompassing the stealth tip (otherwise, the tip is scaled too large).

SurroundingRectangle

围绕目标的矩形框:自动留边距包围对象,强调、圈选必备。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "Polygon"; "Polygon" -> "Rectangle"; "Rectangle" -> "RoundedRectangle"; "RoundedRectangle" -> "SurroundingRectangle"; }

参数

color

ManimColor('#FFFF00'),ParsableManimColor

buff

0.1

corner_radius

0.0,float

快速上手

box = SurroundingRectangle(formula, color=YELLOW)

API 文档

class manim.SurroundingRectangle(*mobjects: Mobject, color: ManimColor | int | str | NDArray[int64] | tuple[int, int, int] | NDArray[float64] | tuple[float, float, float] | tuple[int, int, int, int] | tuple[float, float, float, float] = ManimColor('#FFFF00'), buff: float | tuple[float, float] = 0.1, corner_radius: float = 0.0, **kwargs: Any)

基类:RoundedRectangle

A rectangle surrounding a Mobject

Examples

class SurroundingRectExample(Scene):
    def construct(self):
        title = Title("A Quote from Newton")
        quote = Text(
            "If I have seen further than others, \n"
            "it is by standing upon the shoulders of giants.",
            color=BLUE,
        ).scale(0.75)
        box = SurroundingRectangle(quote, color=YELLOW, buff=MED_LARGE_BUFF)

        t2 = Tex(r"Hello World").scale(1.5)
        box2 = SurroundingRectangle(t2, corner_radius=0.2)
        mobjects = VGroup(VGroup(box, quote), VGroup(t2, box2)).arrange(DOWN)
        self.add(title, mobjects)

TangentLine

曲线在指定参数处的切线:微分几何可视化直接可用。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Line"; "Line" -> "TangentLine"; }

参数

vmob

—,VMobject

alpha

—,float

length

1,float

d_alpha

1e-06,float

快速上手

t = TangentLine(circle, alpha=0.3)

API 文档

class manim.TangentLine(vmob: VMobject, alpha: float, length: float = 1, d_alpha: float = 1e-06, **kwargs: Any)

基类:Line

Constructs a line tangent to a VMobject at a specific point.

Parameters

vmob

The VMobject on which the tangent line is drawn.

alpha

How far along the shape that the line will be constructed. range: 0-1.

length

Length of the tangent line.

d_alpha

The dx value

kwargs

Additional arguments to be passed to Line

Examples

class TangentLineExample(Scene):
    def construct(self):
        circle = Circle(radius=2)
        line_1 = TangentLine(circle, alpha=0.0, length=4, color=BLUE_D) # right
        line_2 = TangentLine(circle, alpha=0.4, length=4, color=GREEN) # top left
        self.add(circle, line_1, line_2)

TangentialArc

以一点为端点、与曲线相切的弧:强调方向变化的小装饰。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Arc"; "Arc" -> "ArcBetweenPoints"; "ArcBetweenPoints" -> "TangentialArc"; }

参数

line1

—,Line

line2

—,Line

radius

—,float

corner

(1, 1),Any

API 文档

class manim.TangentialArc(line1: Line, line2: Line, radius: float, corner: Any = (1, 1), **kwargs: Any)

基类:ArcBetweenPoints

Construct an arc that is tangent to two intersecting lines. You can choose any of the 4 possible corner arcs via the corner tuple. corner = (s1, s2) where each si is ±1 to control direction along each line.

Examples

class TangentialArcExample(Scene):
    def construct(self):
        line1 = DashedLine(start=3 * LEFT, end=3 * RIGHT)
        line1.rotate(angle=31 * DEGREES, about_point=ORIGIN)
        line2 = DashedLine(start=3 * UP, end=3 * DOWN)
        line2.rotate(angle=12 * DEGREES, about_point=ORIGIN)

        arc = TangentialArc(line1, line2, radius=2.25, corner=(1, 1), color=TEAL)
        self.add(arc, line1, line2)

The following example shows all four possible corner configurations:

class TangentialArcCorners(Scene):
    def construct(self):
        # Create two intersecting lines
        line1 = DashedLine(start=3 * LEFT, end=3 * RIGHT, color=GREY)
        line2 = DashedLine(start=3 * UP, end=3 * DOWN, color=GREY)

        # All four corner configurations with different colors
        arc_pp = TangentialArc(line1, line2, radius=1.5, corner=(1, 1), color=RED)
        arc_pn = TangentialArc(line1, line2, radius=1.5, corner=(1, -1), color=GREEN)
        arc_np = TangentialArc(line1, line2, radius=1.5, corner=(-1, 1), color=BLUE)
        arc_nn = TangentialArc(line1, line2, radius=1.5, corner=(-1, -1), color=YELLOW)

        # Labels for each arc
        label_pp = Text("(1,1)", font_size=24, color=RED).next_to(arc_pp, UR, buff=0.1)
        label_pn = Text("(1,-1)", font_size=24, color=GREEN).next_to(arc_pn, DR, buff=0.1)
        label_np = Text("(-1,1)", font_size=24, color=BLUE).next_to(arc_np, UL, buff=0.1)
        label_nn = Text("(-1,-1)", font_size=24, color=YELLOW).next_to(arc_nn, DL, buff=0.1)

        self.add(line1, line2, arc_pp, arc_pn, arc_np, arc_nn)
        self.add(label_pp, label_pn, label_np, label_nn)

TipableVMobject

「可装箭尖」线段的基类:Arrow、Line 继承它获得 add_tip/tip 配置能力。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; }

参数

tip_length

0.35,float

normal_vector

array([0., 0., 1.]),Vector3DLike

tip_style

None,dict | None

API 文档

class manim.TipableVMobject(tip_length: float = 0.35, normal_vector: Vector3DLike = array([0., 0., 1.]), tip_style: dict | None = None, **kwargs: Any)

基类:VMobject

Meant for shared functionality between Arc and Line. Functionality can be classified broadly into these groups:

  • Adding, Creating, Modifying tips
    • add_tip calls create_tip, before pushing the new tip

      into the TipableVMobject's list of submobjects

    • stylistic and positional configuration

  • Checking for tips
    • Boolean checks for whether the TipableVMobject has a tip

      and a starting tip

  • Getters
    • Straightforward accessors, returning information pertaining

      to the TipableVMobject instance's tip(s), its length etc

add_tip(tip: tips.ArrowTip | None = None, tip_shape: type[tips.ArrowTip] | None = None, tip_length: float | None = None, tip_width: float | None = None, at_start: bool = False) → Self

Adds a tip to the TipableVMobject instance, recognising that the endpoints might need to be switched if it's a 'starting tip' or not.

create_tip(tip_shape: type[tips.ArrowTip] | None = None, tip_length: float | None = None, tip_width: float | None = None, at_start: bool = False) → tips.ArrowTip

Stylises the tip, positions it spatially, and returns the newly instantiated tip to the caller.

get_end() → Point3D

Returns the point, where the stroke that surrounds the Mobject ends.

get_start() → Point3D

Returns the point, where the stroke that surrounds the Mobject starts.

get_tip() → VMobject

Returns the TipableVMobject instance's (first) tip, otherwise throws an exception.

get_tips() → VGroup

Returns a VGroup (collection of VMobjects) containing the TipableVMObject instance's tips.

get_unpositioned_tip(tip_shape: type[tips.ArrowTip] | None = None, tip_length: float | None = None, tip_width: float | None = None) → tips.ArrowTip | tips.ArrowTriangleFilledTip

Returns a tip that has been stylistically configured, but has not yet been given a position in space.

Triangle

等边三角形:RegularPolygon(n=3) 的便捷版。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Polygram"; "Polygram" -> "RegularPolygram"; "RegularPolygram" -> "RegularPolygon"; "RegularPolygon" -> "Triangle"; }

快速上手

tri = Triangle()

API 文档

class manim.Triangle(**kwargs: Any)

基类:RegularPolygon

An equilateral triangle.

Parameters

kwargs

Additional arguments to be passed to RegularPolygon

Examples

class TriangleExample(Scene):
    def construct(self):
        triangle_1 = Triangle()
        triangle_2 = Triangle().scale(2).rotate(60*DEGREES)
        tri_group = Group(triangle_1, triangle_2).arrange(buff=1)
        self.add(tri_group)

Underline

下划线:贴住目标底部的横线,强调文本用。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Line"; "Line" -> "Underline"; }

参数

mobject

—,Mobject

buff

0.1,float

快速上手

u = Underline(text)

API 文档

class manim.Underline(mobject: Mobject, buff: float = 0.1, **kwargs: Any)

基类:Line

Creates an underline.

Examples

class UnderLine(Scene):
    def construct(self):
        man = Tex("Manim")  # Full Word
        ul = Underline(man)  # Underlining the word
        self.add(man, ul)

Union

布尔并集:合并两个图形为一个轮廓。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "Union"; }

快速上手

u = Union(square, circle)

API 文档

class manim.Union(*vmobjects: VMobject, **kwargs: Any)

基类:_BooleanOps

Union of two or more VMobject s. This returns the common region of the VMobject s.

Parameters

vmobjects

The VMobject s to find the union of.

Raises

ValueError

If less than 2 VMobject s are passed.

Example

class UnionExample(Scene):
    def construct(self):
        sq = Square(color=RED, fill_opacity=1)
        sq.move_to([-2, 0, 0])
        cr = Circle(color=BLUE, fill_opacity=1)
        cr.move_to([-1.3, 0.7, 0])
        un = Union(sq, cr, color=GREEN, fill_opacity=1)
        un.move_to([1.5, 0.3, 0])
        self.add(sq, cr, un)

Vector

从原点出发的箭头(向量):direction 与长度构造,线性代数可视化核心对象。

继承关系

digraph G { graph [rankdir=LR, bgcolor="transparent", splines=spline, concentrate=true, nodesep="0.15", ranksep="0.3"]; node [shape=box, penwidth=0, width=0.05, height=0.05, margin=0.05]; edge [penwidth=1]; "Mobject" -> "VMobject"; "VMobject" -> "TipableVMobject"; "TipableVMobject" -> "Line"; "Line" -> "Arrow"; "Arrow" -> "Vector"; }

参数

direction

array([1., 0., 0.])

buff

0,float

快速上手

v = Vector(RIGHT * 2, color=RED)

API 文档

class manim.Vector(direction: Vector2DLike | Vector3DLike = array([1., 0., 0.]), buff: float = 0, **kwargs: Any)

基类:Arrow

A vector specialized for use in graphs.

小心

Do not confuse with the Vector2D, Vector3D or VectorND type aliases, which are not Mobjects!

Parameters

direction

The direction of the arrow.

buff

The distance of the vector from its endpoints.

kwargs

Additional arguments to be passed to Arrow

Examples

class VectorExample(Scene):
    def construct(self):
        plane = NumberPlane()
        vector_1 = Vector([1,2])
        vector_2 = Vector([-5,-2])
        self.add(plane, vector_1, vector_2)
coordinate_label(integer_labels: bool = True, n_dim: int = 2, color: ParsableManimColor | None = None, **kwargs: Any) → Matrix

Creates a label based on the coordinates of the vector.

Parameters
integer_labels

Whether or not to round the coordinates to integers.

n_dim

The number of dimensions of the vector.

color

Sets the color of label, optional.

kwargs

Additional arguments to be passed to Matrix.

Returns
Matrix

The label.

Examples
class VectorCoordinateLabel(Scene):
    def construct(self):
        plane = NumberPlane()

        vec_1 = Vector([1, 2])
        vec_2 = Vector([-3, -2])
        label_1 = vec_1.coordinate_label()
        label_2 = vec_2.coordinate_label(color=YELLOW)

        self.add(plane, vec_1, vec_2, label_1, label_2)