API 参考:三维对象(three_d)

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

Arrow3D

三维箭头:空间中的方向向量表示。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Surface Surface VGroup->Surface Cylinder Cylinder Surface->Cylinder Line3D Line3D Cylinder->Line3D Arrow3D Arrow3D Line3D->Arrow3D

参数

start

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

end

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

thickness

0.02,float

height

0.3,float

base_radius

0.08,float

color

ManimColor('#FFFFFF'),ParsableManimColor

resolution

24,int | tuple[int, int]

快速上手

a3 = Arrow3D(ORIGIN, [1, 1, 1])

API 文档

class manim.Arrow3D(start: Point3DLike = array([-1., 0., 0.]), end: Point3DLike = array([1., 0., 0.]), thickness: float = 0.02, height: float = 0.3, base_radius: float = 0.08, color: ParsableManimColor = ManimColor('#FFFFFF'), resolution: int | tuple[int, int] = 24, **kwargs: Any)

基类:Line3D

get_end() → ndarray

Returns the ending point of the Line3D.

Returns

endnumpy.array

Ending point of the Line3D.

Cone

圆锥体:底面半径 + 高度,3D 几何基本体。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Surface Surface VGroup->Surface Cone Cone Surface->Cone

参数

base_radius

1,float

height

1,float

direction

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

show_base

False,bool

v_range

(0, 6.283185307179586),tuple[float, float]

u_min

0,float

checkerboard_colors

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.array

Points defining the Cone.

get_direction() → Vector3D

Returns the current direction of the apex of the Cone.

Returns

directionnumpy.array

The direction of the apex.

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.

set_direction(direction: Vector3DLike) → Self

Changes the direction of the apex of the Cone.

Parameters

direction

The direction of the apex.

ConvexHull3D

三维点集的凸包多面体,计算几何 3D 版。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Polyhedron Polyhedron VGroup->Polyhedron ConvexHull3D ConvexHull3D Polyhedron->ConvexHull3D

参数

API 文档

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

基类:Polyhedron

Cube

立方体:边长指定,可显示面与棱,3D 入门第一件。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Cube Cube VGroup->Cube

参数

side_length

2,float

fill_opacity

0.75,float

fill_color

ManimColor('#58C4DD'),ParsableManimColor

stroke_width

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

generate_points() → Self

Creates the sides of the Cube.

Cylinder

圆柱体:半径 + 高度。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Surface Surface VGroup->Surface Cylinder Cylinder Surface->Cylinder

参数

radius

1,float

height

2,float

direction

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

v_range

(0, 6.283185307179586),tuple[float, float]

show_ends

True,bool

resolution

(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.ndarray

Points defining the Cylinder.

get_direction() → ndarray

Returns the direction of the central axis of the Cylinder.

Returns

directionnumpy.array

The direction of the central axis of the Cylinder.

set_direction(direction: Vector3DLike) → Self

Sets the direction of the central axis of the Cylinder.

Parameters

directionnumpy.array

The direction of the central axis of the Cylinder.

Dodecahedron

十二面体:12 个五边形面的正多面体,Polyhedron 的预制实例。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Polyhedron Polyhedron VGroup->Polyhedron Dodecahedron Dodecahedron Polyhedron->Dodecahedron

参数

API 文档

class manim.Dodecahedron(edge_length: float = 1, **kwargs: Any)

基类:Polyhedron

Dot3D

三维空间中的小圆点:标记空间坐标用。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Surface Surface VGroup->Surface Sphere Sphere Surface->Sphere Dot3D Dot3D Sphere->Dot3D

参数

point

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

radius

0.08,float

color

ManimColor('#FFFFFF'),ParsableManimColor

resolution

(8, 8)

API 文档

class manim.Dot3D(point: Point3D = array([0., 0., 0.]), radius: float = 0.08, color: ParsableManimColor = ManimColor('#FFFFFF'), resolution: int | tuple[int, int] | None = (8, 8), **kwargs: Any)

基类:Sphere

Icosahedron

二十面体:20 个三角面的正多面体。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Polyhedron Polyhedron VGroup->Polyhedron Icosahedron Icosahedron Polyhedron->Icosahedron

参数

API 文档

class manim.Icosahedron(edge_length: float = 1, **kwargs: Any)

基类:Polyhedron

Line3D

空间直线:两点连线,3D 构图骨架。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Surface Surface VGroup->Surface Cylinder Cylinder Surface->Cylinder Line3D Line3D Cylinder->Line3D

参数

start

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

end

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

thickness

0.02,float

color

None

resolution

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

endnumpy.array

Ending point of the Line3D.

get_start() → Point3D

Returns the starting point of the Line3D.

Returns

startnumpy.array

Starting point of the Line3D.

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

Line3D

Line 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

Line3D

Line 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)
pointify(mob_or_point: Mobject | Point3DLike, direction: Vector3DLike | None = None) → Point3D

Gets a point representing the center of the Mobjects.

Parameters

mob_or_point

Mobjects or point whose center should be returned.

direction

If an edge of a Mobjects should be returned, the direction of the edge.

Returns

numpy.array

Center of the Mobjects or point, or edge if direction is given.

set_start_and_end_attrs(start: Point3DLike, end: Point3DLike, **kwargs: Any) → Self

Sets the start and end points of the line.

If either start or end are Mobjects, this gives their centers.

Parameters

start

Starting point or Mobject.

end

Ending point or Mobject.

Octahedron

八面体:8 个三角面的正多面体。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Polyhedron Polyhedron VGroup->Polyhedron Octahedron Octahedron Polyhedron->Octahedron

参数

API 文档

class manim.Octahedron(edge_length: float = 1, **kwargs: Any)

基类:Polyhedron

Polyhedron

通用多面体:顶点列表 + 面列表定义任意凸多面体,正多面体家族由此派生。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Polyhedron Polyhedron VGroup->Polyhedron

参数

vertex_coords

—,Point3DLike_Array

faces_list

—,list[list[int]]

faces_config

{}

graph_config

{},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

棱柱:正多边形底面沿法向拉伸而成。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Cube Cube VGroup->Cube Prism Prism Cube->Prism

参数

API 文档

class manim.Prism(dimensions: Vector3DLike = [3, 2, 1], **kwargs: Any)

基类:Cube

generate_points() → Self

Creates the sides of the Prism.

Sphere

球体:半径指定,可设分辨率,3D 最常用实体。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Surface Surface VGroup->Surface Sphere Sphere Surface->Sphere

参数

center

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

radius

1,float

resolution

None

u_range

(0, 6.283185307179586),tuple[float, float]

v_range

(0, 3.141592653589793),tuple[float, float]

快速上手

s = Sphere(radius=2, resolution=(24, 24))

API 文档

class manim.Sphere(center: Point3DLike = array([0., 0., 0.]), radius: float = 1, resolution: int | Sequence[int] | None = None, u_range: tuple[float, float] = (0, 6.283185307179586), v_range: tuple[float, float] = (0, 3.141592653589793), **kwargs: Any)

基类:Surface

func(u: float, v: float) → Point3D

The z values defining the Sphere being plotted.

Returns

Point3D

The z values defining the Sphere.

Surface

参数化曲面:uv 网格生成任意曲面,如抛物面,3D 函数可视化核心。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Surface Surface VGroup->Surface

参数

func

—

u_range

(0, 1),tuple[float, float]

v_range

(0, 1),tuple[float, float]

resolution

32,int | Sequence[int]

surface_piece_config

{},dict

fill_color

ManimColor('#29ABCA'),ParsableManimColor

fill_opacity

1.0,float

checkerboard_colors

[ManimColor('#29ABCA'), Man…

stroke_color

ManimColor('#BBBBBB'),ParsableManimColor

stroke_width

0.5,float

should_make_jagged

False,bool

pre_function_handle_to_anchor_scale_factor

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 Surface in 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

Surface

The 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

Surface

The 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 个三角面的正多面体。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Polyhedron Polyhedron VGroup->Polyhedron Tetrahedron Tetrahedron Polyhedron->Tetrahedron

参数

API 文档

class manim.Tetrahedron(edge_length: float = 1, **kwargs: Any)

基类:Polyhedron

ThreeDVMobject

三维矢量对象基类:兼容 2D 渲染的 3D 图形祖先。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject ThreeDVMobject ThreeDVMobject VMobject->ThreeDVMobject

参数

API 文档

class manim.ThreeDVMobject(shade_in_3d: bool = True, **kwargs: Any)

基类:VMobject

Torus

圆环体(救生圈面):主半径 + 管半径。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VGroup VGroup VMobject->VGroup Surface Surface VGroup->Surface Torus Torus Surface->Torus

参数

major_radius

3,float

minor_radius

1,float

u_range

(0, 6.283185307179586),tuple[float, float]

v_range

(0, 6.283185307179586),tuple[float, float]

resolution

None

快速上手

t = Torus(major_radius=2, minor_radius=0.5)

API 文档

class manim.Torus(major_radius: float = 3, minor_radius: float = 1, u_range: tuple[float, float] = (0, 6.283185307179586), v_range: tuple[float, float] = (0, 6.283185307179586), resolution: int | tuple[int, int] | None = None, **kwargs: Any)

基类:Surface

func(u: float, v: float) → Point3D

The z values defining the Torus being plotted.

Returns

numpy.ndarray

The z values defining the Torus.