API 参考:三维对象(three_d)¶
共 17 个类,按字母排序。每个类含中文说明、继承链、参数表与上手示例,API 文档由 autodoc 从 manim v0.21.0 源码自动生成;带完整中文精讲的类见 API 索引。
Arrow3D¶
三维箭头:空间中的方向向量表示。
继承关系¶
参数¶
|
array([-1., 0., 0.]),Point3DLike |
|---|---|
|
array([1., 0., 0.]),Point3DLike |
|
0.02,float |
|
0.3,float |
|
0.08,float |
|
ManimColor('#FFFFFF'),ParsableManimColor |
|
24,int | tuple[int, int] |
快速上手¶
a3 = Arrow3D(ORIGIN, [1, 1, 1])
API 文档¶
Cone¶
圆锥体:底面半径 + 高度,3D 几何基本体。
继承关系¶
参数¶
|
1,float |
|---|---|
|
1,float |
|
array([0., 0., 1.]),Vector3DLike |
|
False,bool |
|
(0, 6.283185307179586),tuple[float, float] |
|
0,float |
|
False |
快速上手¶
cone = Cone(direction=Z_AXIS)
API 文档¶
- class manim.Cone(base_radius: float = 1, height: float = 1, direction: Vector3DLike = array([0., 0., 1.]), show_base: bool = False, v_range: tuple[float, float] = (0, 6.283185307179586), u_min: float = 0, checkerboard_colors: Iterable[ParsableManimColor] | Literal[False] = False, **kwargs: Any)¶
基类:
Surface- func(u: float, v: float) Point3D¶
Converts from spherical coordinates to cartesian.
Parameters¶
- u
The radius.
- v
The azimuthal angle.
Returns¶
numpy.arrayPoints defining the
Cone.
ConvexHull3D¶
三维点集的凸包多面体,计算几何 3D 版。
继承关系¶
参数¶
API 文档¶
- class manim.ConvexHull3D(*points: Point3D, tolerance: float = 1e-05, **kwargs: Any)¶
基类:
Polyhedron
Cube¶
立方体:边长指定,可显示面与棱,3D 入门第一件。
继承关系¶
参数¶
|
2,float |
|---|---|
|
0.75,float |
|
ManimColor('#58C4DD'),ParsableManimColor |
|
0,float |
快速上手¶
cube = Cube(side_length=2)
API 文档¶
- class manim.Cube(side_length: float = 2, fill_opacity: float = 0.75, 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'), stroke_width: float = 0, **kwargs: Any)¶
基类:
VGroup
Cylinder¶
圆柱体:半径 + 高度。
继承关系¶
参数¶
|
1,float |
|---|---|
|
2,float |
|
array([0., 0., 1.]),Vector3DLike |
|
(0, 6.283185307179586),tuple[float, float] |
|
True,bool |
|
(24, 24),int | tuple[int, int] |
快速上手¶
cyl = Cylinder(radius=1, height=2)
API 文档¶
- class manim.Cylinder(radius: float = 1, height: float = 2, direction: Vector3DLike = array([0., 0., 1.]), v_range: tuple[float, float] = (0, 6.283185307179586), show_ends: bool = True, resolution: int | tuple[int, int] = (24, 24), **kwargs: Any)¶
基类:
Surface- add_bases() Self¶
Adds the end caps of the cylinder.
- func(u: float, v: float) ndarray¶
Converts from cylindrical coordinates to cartesian.
Parameters¶
- u
The height.
- v
The azimuthal angle.
Returns¶
numpy.ndarrayPoints defining the
Cylinder.
Dodecahedron¶
十二面体:12 个五边形面的正多面体,Polyhedron 的预制实例。
继承关系¶
参数¶
API 文档¶
- class manim.Dodecahedron(edge_length: float = 1, **kwargs: Any)¶
基类:
Polyhedron
Dot3D¶
三维空间中的小圆点:标记空间坐标用。
继承关系¶
参数¶
|
array([0., 0., 0.]),Point3D |
|---|---|
|
0.08,float |
|
ManimColor('#FFFFFF'),ParsableManimColor |
|
(8, 8) |
API 文档¶
Icosahedron¶
二十面体:20 个三角面的正多面体。
继承关系¶
参数¶
API 文档¶
- class manim.Icosahedron(edge_length: float = 1, **kwargs: Any)¶
基类:
Polyhedron
Line3D¶
空间直线:两点连线,3D 构图骨架。
继承关系¶
参数¶
|
array([-1., 0., 0.]),Point3DLike |
|---|---|
|
array([1., 0., 0.]),Point3DLike |
|
0.02,float |
|
None |
|
24,int | tuple[int, int] |
快速上手¶
l3 = Line3D(ORIGIN, [2, 2, 2])
API 文档¶
- class manim.Line3D(start: Point3DLike = array([-1., 0., 0.]), end: Point3DLike = array([1., 0., 0.]), thickness: float = 0.02, color: ParsableManimColor | None = None, resolution: int | tuple[int, int] = 24, **kwargs: Any)¶
基类:
Cylinder- get_end() Point3D¶
Returns the ending point of the
Line3D.Returns¶
- end
numpy.array Ending point of the
Line3D.
- end
- get_start() Point3D¶
Returns the starting point of the
Line3D.Returns¶
- start
numpy.array Starting point of the
Line3D.
- start
- classmethod parallel_to(line: Line3D, point: Point3DLike = array([0., 0., 0.]), length: float = 5, **kwargs: Any) Line3D¶
Returns a line parallel to another line going through a given point.
Parameters¶
- line
The line to be parallel to.
- point
The point to pass through.
- length
Length of the parallel line.
- kwargs
Additional parameters to be passed to the class.
Returns¶
Line3DLine parallel to
line.
Examples¶
class ParallelLineExample(ThreeDScene): def construct(self): self.set_camera_orientation(PI / 3, -PI / 4) ax = ThreeDAxes((-5, 5), (-5, 5), (-5, 5), 10, 10, 10) line1 = Line3D(RIGHT * 2, UP + OUT, color=RED) line2 = Line3D.parallel_to(line1, color=YELLOW) self.add(ax, line1, line2)
- classmethod perpendicular_to(line: Line3D, point: Point3DLike = array([0., 0., 0.]), length: float = 5, **kwargs: Any) Line3D¶
Returns a line perpendicular to another line going through a given point.
Parameters¶
- line
The line to be perpendicular to.
- point
The point to pass through.
- length
Length of the perpendicular line.
- kwargs
Additional parameters to be passed to the class.
Returns¶
Line3DLine perpendicular to
line.
Examples¶
class PerpLineExample(ThreeDScene): def construct(self): self.set_camera_orientation(PI / 3, -PI / 4) ax = ThreeDAxes((-5, 5), (-5, 5), (-5, 5), 10, 10, 10) line1 = Line3D(RIGHT * 2, UP + OUT, color=RED) line2 = Line3D.perpendicular_to(line1, color=BLUE) self.add(ax, line1, line2)
Octahedron¶
八面体:8 个三角面的正多面体。
继承关系¶
参数¶
API 文档¶
- class manim.Octahedron(edge_length: float = 1, **kwargs: Any)¶
基类:
Polyhedron
Polyhedron¶
通用多面体:顶点列表 + 面列表定义任意凸多面体,正多面体家族由此派生。
继承关系¶
参数¶
|
|
|---|---|
|
—,list[list[int]] |
|
{} |
|
{},dict[str, Any] |
API 文档¶
- class manim.Polyhedron(vertex_coords: Point3DLike_Array, faces_list: list[list[int]], faces_config: dict[str, str | int | float | bool] = {}, graph_config: dict[str, Any] = {})¶
基类:
VGroup- create_faces(face_coords: Point3DLike_Array) VGroup¶
Creates VGroup of faces from a list of face coordinates.
- extract_face_coords() Point3DLike_Array¶
Extracts the coordinates of the vertices in the graph. Used for updating faces.
- get_edges(faces_list: list[list[int]]) list[tuple[int, int]]¶
Creates list of cyclic pairwise tuples.
Prism¶
棱柱:正多边形底面沿法向拉伸而成。
继承关系¶
参数¶
API 文档¶
Sphere¶
球体:半径指定,可设分辨率,3D 最常用实体。
继承关系¶
参数¶
|
array([0., 0., 0.]),Point3DLike |
|---|---|
|
1,float |
|
None |
|
(0, 6.283185307179586),tuple[float, float] |
|
(0, 3.141592653589793),tuple[float, float] |
快速上手¶
s = Sphere(radius=2, resolution=(24, 24))
API 文档¶
Surface¶
参数化曲面:uv 网格生成任意曲面,如抛物面,3D 函数可视化核心。
继承关系¶
参数¶
|
— |
|---|---|
|
(0, 1),tuple[float, float] |
|
(0, 1),tuple[float, float] |
|
32,int | Sequence[int] |
|
{},dict |
|
ManimColor('#29ABCA'),ParsableManimColor |
|
1.0,float |
|
[ManimColor('#29ABCA'), Man… |
|
ManimColor('#BBBBBB'),ParsableManimColor |
|
0.5,float |
|
False,bool |
|
1e-05,float |
快速上手¶
surf = Surface(lambda u, v: [u, v, u*u + v*v], u_range=[-1, 1], v_range=[-1, 1])
API 文档¶
- class manim.Surface(func: Callable[[float, float], ndarray], u_range: tuple[float, float] = (0, 1), v_range: tuple[float, float] = (0, 1), resolution: int | Sequence[int] = 32, surface_piece_config: dict = {}, 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('#29ABCA'), fill_opacity: float = 1.0, checkerboard_colors: Iterable[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]] | Literal[False] = [ManimColor('#29ABCA'), ManimColor('#236B8E')], 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('#BBBBBB'), stroke_width: float = 0.5, should_make_jagged: bool = False, pre_function_handle_to_anchor_scale_factor: float = 1e-05, **kwargs: Any)¶
基类:
VGroup- set_fill_by_checkerboard(*colors: 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], opacity: float | None = None) Self¶
Sets the fill_color of each face of
Surfacein an alternating pattern.Parameters¶
- colors
List of colors for alternating pattern.
- opacity
The fill_opacity of
Surface, from 0 being fully transparent to 1 being fully opaque.
Returns¶
SurfaceThe parametric surface with an alternating pattern.
- set_fill_by_value(axes: ThreeDAxes, colorscale: Iterable[ParsableManimColor] | Iterable[tuple[ParsableManimColor, float]] | None = None, axis: int = 2, **kwargs: Any) Self¶
Sets the color of each mobject of a parametric surface to a color relative to its axis-value.
Parameters¶
- axes
The axes for the parametric surface, which will be used to map axis-values to colors.
- colorscale
A list of colors, ordered from lower axis-values to higher axis-values. If a list of tuples is passed containing colors paired with numbers, then those numbers will be used as the pivots.
- axis
The chosen axis to use for the color mapping. (0 = x, 1 = y, 2 = z)
Returns¶
SurfaceThe parametric surface with a gradient applied by value. For chaining.
Examples¶
class FillByValueExample(ThreeDScene): def construct(self): resolution_fa = 8 self.set_camera_orientation(phi=75 * DEGREES, theta=-160 * DEGREES) axes = ThreeDAxes(x_range=(0, 5, 1), y_range=(0, 5, 1), z_range=(-1, 1, 0.5)) def param_surface(u, v): x = u y = v z = np.sin(x) * np.cos(y) return z surface_plane = Surface( lambda u, v: axes.c2p(u, v, param_surface(u, v)), resolution=(resolution_fa, resolution_fa), v_range=[0, 5], u_range=[0, 5], ) surface_plane.set_style(fill_opacity=1) surface_plane.set_fill_by_value(axes=axes, colorscale=[(RED, -0.5), (YELLOW, 0), (GREEN, 0.5)], axis=2) self.add(axes, surface_plane)
Tetrahedron¶
四面体:4 个三角面的正多面体。
继承关系¶
参数¶
API 文档¶
- class manim.Tetrahedron(edge_length: float = 1, **kwargs: Any)¶
基类:
Polyhedron
ThreeDVMobject¶
三维矢量对象基类:兼容 2D 渲染的 3D 图形祖先。
继承关系¶
参数¶
API 文档¶
Torus¶
圆环体(救生圈面):主半径 + 管半径。
继承关系¶
参数¶
|
3,float |
|---|---|
|
1,float |
|
(0, 6.283185307179586),tuple[float, float] |
|
(0, 6.283185307179586),tuple[float, float] |
|
None |
快速上手¶
t = Torus(major_radius=2, minor_radius=0.5)