API 参考:三维对象(three_d)

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

Arrow3D

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

继承关系

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" -> "Surface"; "Surface" -> "Cylinder"; "Cylinder" -> "Line3D"; "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

An arrow made out of a cylindrical line and a conical tip.

Parameters

start

The start position of the arrow.

end

The end position of the arrow.

thickness

The thickness of the arrow.

height

The height of the conical tip.

base_radius

The base radius of the conical tip.

color

The color of the arrow.

resolution

The resolution of the arrow line.

Examples

class ExampleArrow3D(ThreeDScene):
    def construct(self):
        axes = ThreeDAxes()
        arrow = Arrow3D(
            start=np.array([0, 0, 0]),
            end=np.array([2, 2, 2]),
            resolution=8
        )
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        self.add(axes, arrow)
get_end() → ndarray

Returns the ending point of the Line3D.

Returns
endnumpy.array

Ending point of the Line3D.

Cone

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

继承关系

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" -> "Surface"; "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

A circular cone. Can be defined using 2 parameters: its height, and its base radius. The polar angle, theta, can be calculated using arctan(base_radius / height) The spherical radius, r, is calculated using the pythagorean theorem.

Parameters

base_radius

The base radius from which the cone tapers.

height

The height measured from the plane formed by the base_radius to the apex of the cone.

direction

The direction of the apex.

show_base

Whether to show the base plane or not.

v_range

The azimuthal angle to start and end at.

u_min

The radius at the apex.

checkerboard_colors

Show checkerboard grid texture on the cone.

Examples

class ExampleCone(ThreeDScene):
    def construct(self):
        axes = ThreeDAxes()
        cone = Cone(direction=X_AXIS+Y_AXIS+2*Z_AXIS, resolution=8)
        self.set_camera_orientation(phi=5*PI/11, theta=PI/9)
        self.add(axes, cone)
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 版。

继承关系

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" -> "Polyhedron"; "Polyhedron" -> "ConvexHull3D"; }

参数

API 文档

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

基类:Polyhedron

A convex hull for a set of points

Parameters

points

The points to consider.

tolerance

The tolerance used for quickhull.

kwargs

Forwarded to the parent constructor.

Examples

class ConvexHull3DExample(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        points = [
            [ 1.93192757,  0.44134585, -1.52407061],
            [-0.93302521,  1.23206983,  0.64117067],
            [-0.44350918, -0.61043677,  0.21723705],
            [-0.42640268, -1.05260843,  1.61266094],
            [-1.84449637,  0.91238739, -1.85172623],
            [ 1.72068132, -0.11880457,  0.51881751],
            [ 0.41904805,  0.44938012, -1.86440686],
            [ 0.83864666,  1.66653337,  1.88960123],
            [ 0.22240514, -0.80986286,  1.34249326],
            [-1.29585759,  1.01516189,  0.46187522],
            [ 1.7776499,  -1.59550796, -1.70240747],
            [ 0.80065226, -0.12530398,  1.70063977],
            [ 1.28960948, -1.44158255,  1.39938582],
            [-0.93538943,  1.33617705, -0.24852643],
            [-1.54868271,  1.7444399,  -0.46170734]
        ]
        hull = ConvexHull3D(
            *points,
            faces_config = {"stroke_opacity": 0},
            graph_config = {
                "vertex_type": Dot3D,
                "edge_config": {
                    "stroke_color": BLUE,
                    "stroke_width": 2,
                    "stroke_opacity": 0.05,
                }
            }
        )
        dots = VGroup(*[Dot3D(point) for point in points])
        self.add(hull)
        self.add(dots)

Cube

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

继承关系

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" -> "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

A three-dimensional cube.

Parameters

side_length

Length of each side of the Cube.

fill_opacity

The opacity of the Cube, from 0 being fully transparent to 1 being fully opaque. Defaults to 0.75.

fill_color

The color of the Cube.

stroke_width

The width of the stroke surrounding each face of the Cube.

Examples

class CubeExample(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=75*DEGREES, theta=-45*DEGREES)

        axes = ThreeDAxes()
        cube = Cube(side_length=3, fill_opacity=0.7, fill_color=BLUE)
        self.add(cube)
generate_points() → Self

Creates the sides of the Cube.

Cylinder

圆柱体:半径 + 高度。

继承关系

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" -> "Surface"; "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

A cylinder, defined by its height, radius and direction,

Parameters

radius

The radius of the cylinder.

height

The height of the cylinder.

direction

The direction of the central axis of the cylinder.

v_range

The height along the height axis (given by direction) to start and end on.

show_ends

Whether to show the end caps or not.

resolution

The number of samples taken of the Cylinder. A tuple can be used to define different resolutions for u and v respectively.

Examples

class ExampleCylinder(ThreeDScene):
    def construct(self):
        axes = ThreeDAxes()
        cylinder = Cylinder(radius=2, height=3)
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        self.add(axes, cylinder)
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 的预制实例。

继承关系

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" -> "Polyhedron"; "Polyhedron" -> "Dodecahedron"; }

参数

API 文档

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

基类:Polyhedron

A dodecahedron, one of the five platonic solids. It has 12 faces, 30 edges and 20 vertices.

Parameters

edge_length

The length of an edge between any two vertices.

Examples

class DodecahedronScene(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        obj = Dodecahedron()
        self.add(obj)

Dot3D

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

继承关系

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" -> "Surface"; "Surface" -> "Sphere"; "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

A spherical dot.

Parameters

point

The location of the dot.

radius

The radius of the dot.

color

The color of the Dot3D.

resolution

The number of samples taken of the Dot3D. A tuple can be used to define different resolutions for u and v respectively.

Examples

class Dot3DExample(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=75*DEGREES, theta=-45*DEGREES)

        axes = ThreeDAxes()
        dot_1 = Dot3D(point=axes.coords_to_point(0, 0, 1), color=RED)
        dot_2 = Dot3D(point=axes.coords_to_point(2, 0, 0), radius=0.1, color=BLUE)
        dot_3 = Dot3D(point=[0, 0, 0], radius=0.1, color=ORANGE)
        self.add(axes, dot_1, dot_2,dot_3)

Icosahedron

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

继承关系

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" -> "Polyhedron"; "Polyhedron" -> "Icosahedron"; }

参数

API 文档

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

基类:Polyhedron

An icosahedron, one of the five platonic solids. It has 20 faces, 30 edges and 12 vertices.

Parameters

edge_length

The length of an edge between any two vertices.

Examples

class IcosahedronScene(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        obj = Icosahedron()
        self.add(obj)

Line3D

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

继承关系

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" -> "Surface"; "Surface" -> "Cylinder"; "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

A cylindrical line, for use in ThreeDScene.

Parameters

start

The start point of the line.

end

The end point of the line.

thickness

The thickness of the line.

color

The color of the line.

resolution

The resolution of the line. By default this value is the number of points the line will sampled at. If you want the line to also come out checkered, use a tuple. For example, for a line made of 24 points with 4 checker points on each cylinder, pass the tuple (4, 24).

Examples

class ExampleLine3D(ThreeDScene):
    def construct(self):
        axes = ThreeDAxes()
        line = Line3D(start=np.array([0, 0, 0]), end=np.array([2, 2, 2]))
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        self.add(axes, line)
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 个三角面的正多面体。

继承关系

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" -> "Polyhedron"; "Polyhedron" -> "Octahedron"; }

参数

API 文档

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

基类:Polyhedron

An octahedron, one of the five platonic solids. It has 8 faces, 12 edges and 6 vertices.

Parameters

edge_length

The length of an edge between any two vertices.

Examples

class OctahedronScene(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        obj = Octahedron()
        self.add(obj)

Polyhedron

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

继承关系

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" -> "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

An abstract polyhedra class.

In this implementation, polyhedra are defined with a list of vertex coordinates in space, and a list of faces. This implementation mirrors that of a standard polyhedral data format (OFF, object file format).

Parameters

vertex_coords

A list of coordinates of the corresponding vertices in the polyhedron. Each coordinate will correspond to a vertex. The vertices are indexed with the usual indexing of Python.

faces_list

A list of faces. Each face is a sublist containing the indices of the vertices that form the corners of that face.

faces_config

Configuration for the polygons representing the faces of the polyhedron.

graph_config

Configuration for the graph containing the vertices and edges of the polyhedron.

Examples

To understand how to create a custom polyhedra, let's use the example of a rather simple one - a square pyramid.

class SquarePyramidScene(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        vertex_coords = [
            [1, 1, 0],
            [1, -1, 0],
            [-1, -1, 0],
            [-1, 1, 0],
            [0, 0, 2]
        ]
        faces_list = [
            [0, 1, 4],
            [1, 2, 4],
            [2, 3, 4],
            [3, 0, 4],
            [0, 1, 2, 3]
        ]
        pyramid = Polyhedron(vertex_coords, faces_list)
        self.add(pyramid)

In defining the polyhedron above, we first defined the coordinates of the vertices. These are the corners of the square base, given as the first four coordinates in the vertex list, and the apex, the last coordinate in the list.

Next, we define the faces of the polyhedron. The triangular surfaces of the pyramid are polygons with two adjacent vertices in the base and the vertex at the apex as corners. We thus define these surfaces in the first four elements of our face list. The last element defines the base of the pyramid.

The graph and faces of polyhedra can also be accessed and modified directly, after instantiation. They are stored in the graph and faces attributes respectively.

class PolyhedronSubMobjects(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        octahedron = Octahedron(edge_length = 3)
        octahedron.graph[0].set_color(RED)
        octahedron.faces[2].set_color(YELLOW)
        self.add(octahedron)
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

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

继承关系

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" -> "Cube"; "Cube" -> "Prism"; }

参数

API 文档

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

基类:Cube

A right rectangular prism (or rectangular cuboid). Defined by the length of each side in [x, y, z] format.

Parameters

dimensions

Dimensions of the Prism in [x, y, z] format.

Examples

class ExamplePrism(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=60 * DEGREES, theta=150 * DEGREES)
        prismSmall = Prism(dimensions=[1, 2, 3]).rotate(PI / 2)
        prismLarge = Prism(dimensions=[1.5, 3, 4.5]).move_to([2, 0, 0])
        self.add(prismSmall, prismLarge)
generate_points() → Self

Creates the sides of the Prism.

Sphere

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

继承关系

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" -> "Surface"; "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

A three-dimensional sphere.

Parameters

center

Center of the Sphere.

radius

The radius of the Sphere.

resolution

The number of samples taken of the Sphere. A tuple can be used to define different resolutions for u and v respectively.

u_range

The range of the u variable: (u_min, u_max).

v_range

The range of the v variable: (v_min, v_max).

Examples

class ExampleSphere(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=PI / 6, theta=PI / 6)
        sphere1 = Sphere(center=(3, 0, 0), radius=1, resolution=(20, 20))
        sphere1.set_color(RED)
        self.add(sphere1)
        sphere2 = Sphere(center=(-1, -3, 0), radius=2, resolution=(18, 18))
        sphere2.set_color(GREEN)
        self.add(sphere2)
        sphere3 = Sphere(center=(-1, 2, 0), radius=2, resolution=(16, 16))
        sphere3.set_color(BLUE)
        self.add(sphere3)

This example shows that overlapping spheres can intersect with rough transitions.

class ExampleSphereOverlap(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=PI / 4, theta=PI / 4)
        sphere1 = Sphere(center=(0, 0, 0), radius=1, resolution=(20, 20))
        sphere1.set_color(RED)
        self.add(sphere1)
        sphere2 = Sphere(center=(-0.5, -1, 0.5), radius=1.2, resolution=(20, 20))
        sphere2.set_color(GREEN)
        self.add(sphere2)
        sphere3 = Sphere(center=(1, -1, 0), radius=1.1, resolution=(20, 20))
        sphere3.set_color(BLUE)
        self.add(sphere3)

In this example, by modifying u_range (the range of the azimuthal angle) and v_range (the range of the polar angle), it is possible to obtain a portion of a sphere:

class ExamplePartialSpheres(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=PI / 4)
        sphere1 = Sphere(
            center=(-3, 0, 0),
            resolution=(10, 20),
            u_range=[TAU / 4, 3 * TAU / 4],
        )
        sphere1.set_color(RED)
        self.add(sphere1)
        sphere2 = Sphere(
            center=(0, 0, 0),
            resolution=(20, 10),
            v_range=[0, TAU / 4],
        )
        sphere2.set_color(GREEN)
        self.add(sphere2)
        sphere3 = Sphere(
            center=(3, 0, 0),
            resolution=(5, 10),
            u_range=[3 * TAU / 4, TAU],
            v_range=[TAU / 4, TAU / 2],
        )
        sphere3.set_color(BLUE)
        self.add(sphere3)
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 函数可视化核心。

继承关系

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" -> "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

Creates a Parametric Surface using a checkerboard pattern.

Parameters

func

The function defining the Surface.

u_range

The range of the u variable: (u_min, u_max).

v_range

The range of the v variable: (v_min, v_max).

resolution

The number of samples taken of the Surface. A tuple can be used to define different resolutions for u and v respectively.

fill_color

The color of the Surface. Ignored if checkerboard_colors is set.

fill_opacity

The opacity of the Surface, from 0 being fully transparent to 1 being fully opaque. Defaults to 1.

checkerboard_colors

ng individual faces alternating colors. Overrides fill_color.

stroke_color

Color of the stroke surrounding each face of Surface.

stroke_width

Width of the stroke surrounding each face of Surface. Defaults to 0.5.

should_make_jagged

Changes the anchor mode of the Bézier curves from smooth to jagged. Defaults to False.

Examples

class ParaSurface(ThreeDScene):
    def func(self, u, v):
        return np.array([np.cos(u) * np.cos(v), np.cos(u) * np.sin(v), u])

    def construct(self):
        axes = ThreeDAxes(x_range=[-4,4], x_length=8)
        surface = Surface(
            lambda u, v: axes.c2p(*self.func(u, v)),
            u_range=[-PI, PI],
            v_range=[0, TAU],
            resolution=8,
        )
        self.set_camera_orientation(theta=70 * DEGREES, phi=75 * DEGREES)
        self.add(axes, surface)
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 个三角面的正多面体。

继承关系

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" -> "Polyhedron"; "Polyhedron" -> "Tetrahedron"; }

参数

API 文档

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

基类:Polyhedron

A tetrahedron, one of the five platonic solids. It has 4 faces, 6 edges, and 4 vertices.

Parameters

edge_length

The length of an edge between any two vertices.

Examples

class TetrahedronScene(ThreeDScene):
    def construct(self):
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        obj = Tetrahedron()
        self.add(obj)

ThreeDVMobject

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

继承关系

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" -> "ThreeDVMobject"; }

参数

API 文档

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

基类:VMobject

Torus

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

继承关系

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" -> "Surface"; "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

A torus.

Parameters

major_radius

Distance from the center of the tube to the center of the torus.

minor_radius

Radius of the tube.

u_range

The range of the u variable: (u_min, u_max).

v_range

The range of the v variable: (v_min, v_max).

resolution

The number of samples taken of the Torus. A tuple can be used to define different resolutions for u and v respectively.

Examples

class ExampleTorus(ThreeDScene):
    def construct(self):
        axes = ThreeDAxes()
        torus = Torus()
        self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
        self.add(axes, torus)
func(u: float, v: float) → Point3D

The z values defining the Torus being plotted.

Returns
numpy.ndarray

The z values defining the Torus.