API 参考:几何图形(geometry)¶
共 57 个类,按字母排序。每个类含中文说明、继承链、参数表与上手示例,API 文档由 autodoc 从 manim v0.21.0 源码自动生成;带完整中文精讲的类见 API 索引。
Angle¶
两条线的夹角图形:自动找交点、按半径画出夹角弧,可标注度数,几何作图必备。
继承关系¶
参数¶
|
—,Line |
|---|---|
|
—,Line |
|
None,float | None |
|
(1, 1),AngleQuadrant |
|
False,bool |
|
False,bool |
|
None,float | None |
|
0.55,float |
|
ManimColor('#FFFFFF'),ParsableManimColor |
|
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- 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
**kwargsFurther 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
Angleclass.Returns¶
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
Angleclass.Parameters¶
- degrees
A boolean to decide the unit (deg/rad) in which the value of the angle is returned.
Returns¶
floatThe value in degrees/radians of an angle of the
Angleclass.
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 在复杂背景上更醒目,常用于标记点。
继承关系¶
参数¶
|
0.10400000000000001,float |
|---|---|
|
5,float |
|
ManimColor('#FFFFFF'),ParsableManimColor |
|
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
AnnularSector¶
扇环(圆环的一段):内外半径 + 起止角度,饼图环图的基础件。
继承关系¶
参数¶
|
1,float |
|---|---|
|
2,float |
|
1.5707963267948966,float |
|
0,float |
|
1,float |
|
0,float |
|
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- generate_points() Self¶
Initializes
pointsand therefore the shape.Gets called upon creation. This is an empty method that can be implemented by subclasses.
Annulus¶
完整圆环:内半径 + 外半径,甜甜圈形状。
继承关系¶
参数¶
|
1,float |
|---|---|
|
2,float |
|
1,float |
|
0,float |
|
ManimColor('#FFFFFF'),ParsableManimColor |
|
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- generate_points() Self¶
Initializes
pointsand therefore the shape.Gets called upon creation. This is an empty method that can be implemented by subclasses.
Arc¶
圆弧:半径 + 起始角 + 张角,所有曲线类图形(Circle、Sector……)的祖宗。
继承关系¶
参数¶
|
1.0,float | None |
|---|---|
|
0,float |
|
1.5707963267948966,float |
|
9,int |
|
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)¶
-
- generate_points() Self¶
Initializes
pointsand 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¶
过两点的一段圆弧:自动选半径让弧经过两点,画「连接箭头」或「跳跃路径」常用。
继承关系¶
参数¶
|
—,Point3DLike |
|---|---|
|
—,Point3DLike |
|
1.5707963267948966,float |
|
None,float | None |
快速上手¶
arc = ArcBetweenPoints(a.get_center(), b.get_center())
API 文档¶
ArcPolygon¶
边为圆弧的多边形:顶点之间用弧连接而非直线,呈现「鼓包」轮廓。
继承关系¶
参数¶
|
0.7853981633974483,float |
|---|---|
|
None,float | None |
|
None,list[dict] | None |
API 文档¶
ArcPolygonFromArcs¶
用现成 Arc 对象拼成多边形,边完全由你给的弧决定。
继承关系¶
API 文档¶
- class manim.ArcPolygonFromArcs(*arcs: Arc | ArcBetweenPoints, **kwargs: Any)¶
基类:
VMobject
Arrow¶
带箭头的直线:start/end + 箭尖样式 buff 可调,是最常用的指向性图形。
继承关系¶
参数¶
|
6,float |
|---|---|
|
0.25,float |
|
0.25,float |
|
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- 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.
参见
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 的实心版)。
继承关系¶
参数¶
|
1,float |
|---|---|
|
0,float |
API 文档¶
- class manim.ArrowCircleFilledTip(fill_opacity: float = 1, stroke_width: float = 0, **kwargs: Any)¶
ArrowCircleTip¶
空心圆形箭尖样式类:把箭头末端换成小圆圈,思维导图风。
继承关系¶
参数¶
|
0,float |
|---|---|
|
3,float |
|
0.35,float |
|
3.141592653589793,float |
API 文档¶
ArrowSquareFilledTip¶
方形实心箭尖样式类。
继承关系¶
参数¶
|
1,float |
|---|---|
|
0,float |
API 文档¶
- class manim.ArrowSquareFilledTip(fill_opacity: float = 1, stroke_width: float = 0, **kwargs: Any)¶
ArrowSquareTip¶
空心方形箭尖样式类。
继承关系¶
参数¶
|
0,float |
|---|---|
|
3,float |
|
0.35,float |
|
3.141592653589793,float |
API 文档¶
ArrowTip¶
所有箭尖样式的基类:自定义箭尖就继承它实现 set_points(),length/width 属性定义尺寸。
继承关系¶
API 文档¶
- class manim.ArrowTip(*args: Any, **kwargs: Any)¶
基类:
VMobject- 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
ArrowTriangleFilledTip¶
三角实心箭尖(默认样式),一般不直接实例化。
继承关系¶
参数¶
|
1,float |
|---|---|
|
0,float |
API 文档¶
- class manim.ArrowTriangleFilledTip(fill_opacity: float = 1, stroke_width: float = 0, **kwargs: Any)¶
ArrowTriangleTip¶
空心三角箭尖样式类。
继承关系¶
参数¶
|
0,float |
|---|---|
|
3,float |
|
0.35,float |
|
0.35,float |
|
3.141592653589793,float |
API 文档¶
BackgroundRectangle¶
自动包裹目标对象的背景色矩形:给文字图形加底色衬垫,防止与背景混淆。
继承关系¶
参数¶
|
None |
|---|---|
|
0,float |
|
0,float |
|
0.75,float |
|
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)¶
-
- pointwise_become_partial(mobject: Mobject, a: Any, b: float) Self¶
Given a 2nd
VMobjectvmobject, a lower boundaand an upper boundb, modify thisVMobject's points to match the portion of the Bézier spline described byvmobject.pointswith the parametertbetweenaandb.Parameters¶
- vmobject
The
VMobjectthat will serve as a model.- a
The lower bound for
t.- b
The upper bound for
t
Returns¶
Raises¶
- TypeError
If
vmobjectis not an instance ofVMobject.
Circle¶
圆:radius 或 diameter 指定大小,提供 from_three_points、point_at_angle、surround 等几何工厂方法。
继承关系¶
参数¶
|
None,float | None |
|---|---|
|
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- 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.ndarrayThe 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¶
一组点的凸包多边形:自动计算外轮廓,计算几何可视化。
继承关系¶
参数¶
API 文档¶
Cross¶
叉号(×)图形:stroke_width 和比例可调,标记错误或否定语义。
继承关系¶
参数¶
|
None,Mobject | None |
|---|---|
|
ManimColor('#FC6255'),ParsableManimColor |
|
6.0,float |
|
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
CubicBezier¶
三次贝塞尔曲线:两个锚点 + 两个控制点,是矢量绘图的最小单元。
继承关系¶
参数¶
|
—,Point3DLike |
|---|---|
|
—,Point3DLike |
|
—,Point3DLike |
|
—,Point3DLike |
快速上手¶
b = CubicBezier(a1, h1, h2, a2)
API 文档¶
CurvedArrow¶
弯曲的箭头:ArcBetweenPoints + 箭尖的组合体,流程图里绕过障碍的连线。
继承关系¶
参数¶
|
—,Point3DLike |
|---|---|
|
—,Point3DLike |
API 文档¶
- class manim.CurvedArrow(start_point: Point3DLike, end_point: Point3DLike, **kwargs: Any)¶
CurvedDoubleArrow¶
两端都带箭尖的弯弧,双向关系专用。
继承关系¶
参数¶
|
—,Point3DLike |
|---|---|
|
—,Point3DLike |
API 文档¶
- class manim.CurvedDoubleArrow(start_point: Point3DLike, end_point: Point3DLike, **kwargs: Any)¶
基类:
CurvedArrow
Cutout¶
带镂空的多边形:外部轮廓减内部孔洞,fill 模式下孔洞透明。
继承关系¶
参数¶
快速上手¶
c = Cutout(square, circle)
API 文档¶
DashedLine¶
虚线直线:DashedVMobject 的直线便捷版,辅助线首选。
继承关系¶
参数¶
|
0.05,float |
|---|---|
|
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- 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. ])
Difference¶
布尔差集:从主体图形中挖掉重叠部分,属于 VMobject 布尔运算家族。
继承关系¶
参数¶
|
—,VMobject |
|---|---|
|
—,VMobject |
快速上手¶
diff = Difference(square, circle)
API 文档¶
Dot¶
小圆点:radius 很小且 fill 为主,标记坐标、描点画图的基本单元。
继承关系¶
参数¶
|
array([0., 0., 0.]),Point3DLike |
|---|---|
|
0.08,float |
|
0,float |
|
1.0,float |
|
ManimColor('#FFFFFF'),ParsableManimColor |
快速上手¶
dot = Dot(point, color=RED)
API 文档¶
DoubleArrow¶
两端都有箭头的直线,表示双向映射或区间。
继承关系¶
快速上手¶
d = DoubleArrow(LEFT, RIGHT)
API 文档¶
Elbow¶
直角弯头线:两条垂直短线段,管道图、直角坐标标记用。
继承关系¶
参数¶
|
0.2,float |
|---|---|
|
0,float |
API 文档¶
Ellipse¶
椭圆:width/height 分别指定两轴,圆形的长轴版。
继承关系¶
参数¶
|
2,float |
|---|---|
|
1,float |
快速上手¶
e = Ellipse(width=4, height=2)
API 文档¶
Exclusion¶
布尔异或:只保留两个图形不重叠的部分。
继承关系¶
参数¶
|
—,VMobject |
|---|---|
|
—,VMobject |
API 文档¶
Intersection¶
布尔交集:只保留两个图形重叠的区域。
继承关系¶
快速上手¶
i = Intersection(square, circle)
API 文档¶
Label¶
几何图形上的标签:自带背景框的小文本,跟随目标位置摆放。
继承关系¶
参数¶
|
—,str | ManimTextLabel |
|---|---|
|
None,dict[str, Any] | None |
|
None,dict[str, Any] | None |
|
None,dict[str, Any] | None |
API 文档¶
LabeledArrow¶
带文字标签的箭头:label 自动置于箭身中点,省去手动对位。
继承关系¶
API 文档¶
- class manim.LabeledArrow(*args: Any, **kwargs: Any)¶
基类:
LabeledLine,Arrow
LabeledDot¶
带文字标签的圆点:标签居中于点内,图论顶点标注专用。
继承关系¶
参数¶
|
— |
|---|---|
|
None,float | None |
|
0.1,float |
API 文档¶
- class manim.LabeledDot(label: str | SingleStringMathTex | Text | Tex, radius: float | None = None, buff: float = 0.1, **kwargs: Any)¶
基类:
Dot
LabeledLine¶
带标签的直线:标签自动放在线段中点。
继承关系¶
参数¶
|
—,str | ManimTextLabel |
|---|---|
|
0.5,float |
|
None,dict[str, Any] | None |
|
None,dict[str, Any] | None |
|
None,dict[str, Any] | None |
API 文档¶
LabeledPolygram¶
带顶点标签的折线/多边形:每个顶点自动编号。
继承关系¶
参数¶
|
—,str | ManimTextLabel |
|---|---|
|
0.01,float |
|
None,dict[str, Any] | None |
|
None,dict[str, Any] | None |
|
None,dict[str, Any] | None |
API 文档¶
Line¶
两点之间的直线:buff 让端点留白不压对象,put_start_and_end_on 可动画化,是构图的骨架。
继承关系¶
参数¶
|
array([-1., 0., 0.]),Point3DLike | Mobject |
|---|---|
|
array([1., 0., 0.]),Point3DLike | Mobject |
|
0,float |
|
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)¶
-
- generate_points() Self¶
Initializes
pointsand 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¶
多边形:顶点列表连线闭合,一切直边图形(三角形、矩形……)的基类。
继承关系¶
快速上手¶
p = Polygon(ORIGIN, RIGHT, UP)
API 文档¶
Polygram¶
折线组:可以含多个不闭合顶点组(组 = 一条折线),比 Polygon 更自由的连点工具。
继承关系¶
参数¶
API 文档¶
- class manim.Polygram(*vertex_groups: Point3DLike_Array, color: ParsableManimColor = ManimColor('#58C4DD'), **kwargs: Any)¶
基类:
VMobject- 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.ndarrayThe 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 与角半径可调,包围、对齐、底衬的主力图形。
继承关系¶
参数¶
|
ManimColor('#FFFFFF'),ParsableManimColor |
|---|---|
|
2.0,float |
|
4.0,float |
|
None,float | None |
|
None,float | None |
|
True,bool |
|
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
RegularPolygon¶
正多边形:n 指定边数,内切圆半径可调。
继承关系¶
参数¶
快速上手¶
hexagon = RegularPolygon(n=6)
API 文档¶
- class manim.RegularPolygon(n: int = 6, **kwargs: Any)¶
RegularPolygram¶
正多角星:n 顶点按密度跳着连线(如五角星 density=2)。
继承关系¶
参数¶
|
—,int |
|---|---|
|
2,int |
|
1,float |
|
None,float | None |
API 文档¶
RightAngle¶
直角标记:两条线垂直时的小方框角标,几何证明标配。
继承关系¶
参数¶
|
—,Line |
|---|---|
|
—,Line |
|
None,float | None |
快速上手¶
ra = RightAngle(line1, line2, length=0.3)
API 文档¶
RoundedRectangle¶
圆角矩形:corner_radius 控制圆角,卡片式 UI 元素的首选。
继承关系¶
参数¶
快速上手¶
card = RoundedRectangle(corner_radius=0.2, width=4, height=2)
API 文档¶
Sector¶
扇形:圆 + 张角,饼图的组成单元。
继承关系¶
参数¶
快速上手¶
s = Sector(angle=PI/3)
API 文档¶
- class manim.Sector(radius: float = 1, **kwargs: Any)¶
Square¶
正方形:Rectangle 的等边便捷版,边长用 side_length。
继承关系¶
参数¶
快速上手¶
sq = Square(side_length=2)
API 文档¶
Star¶
五角星样式的正多角星:n 与密度决定角数,外内半径比决定胖瘦。
继承关系¶
参数¶
|
5,int |
|---|---|
|
1,float |
|
None,float | None |
|
2,int |
|
1.5707963267948966,float | None |
快速上手¶
star = Star(n=5, fill_color=YELLOW)
API 文档¶
StealthTip¶
隐形战斗机风格的箭尖(默认箭尖),一般不直接实例化。
继承关系¶
参数¶
|
1,float |
|---|---|
|
3,float |
|
0.175,float |
|
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- 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¶
围绕目标的矩形框:自动留边距包围对象,强调、圈选必备。
继承关系¶
参数¶
|
ManimColor('#FFFF00'),ParsableManimColor |
|---|---|
|
0.1 |
|
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)¶
TangentLine¶
曲线在指定参数处的切线:微分几何可视化直接可用。
继承关系¶
参数¶
|
—,VMobject |
|---|---|
|
—,float |
|
1,float |
|
1e-06,float |
快速上手¶
t = TangentLine(circle, alpha=0.3)
API 文档¶
TangentialArc¶
以一点为端点、与曲线相切的弧:强调方向变化的小装饰。
继承关系¶
参数¶
|
—,Line |
|---|---|
|
—,Line |
|
—,float |
|
(1, 1),Any |
API 文档¶
TipableVMobject¶
「可装箭尖」线段的基类:Arrow、Line 继承它获得 add_tip/tip 配置能力。
继承关系¶
参数¶
|
0.35,float |
|---|---|
|
array([0., 0., 1.]),Vector3DLike |
|
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- 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_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) 的便捷版。
继承关系¶
快速上手¶
tri = Triangle()
API 文档¶
- class manim.Triangle(**kwargs: Any)¶
Underline¶
下划线:贴住目标底部的横线,强调文本用。
继承关系¶
参数¶
|
—,Mobject |
|---|---|
|
0.1,float |
快速上手¶
u = Underline(text)
API 文档¶
Union¶
布尔并集:合并两个图形为一个轮廓。
继承关系¶
快速上手¶
u = Union(square, circle)
API 文档¶
Vector¶
从原点出发的箭头(向量):direction 与长度构造,线性代数可视化核心对象。
继承关系¶
参数¶
|
array([1., 0., 0.]) |
|---|---|
|
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- 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¶
MatrixThe 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)