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 文档¶
- 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)¶
基类:
Line3DAn 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)
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)¶
基类:
SurfaceA 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.arrayPoints defining the
Cone.
ConvexHull3D¶
三维点集的凸包多面体,计算几何 3D 版。
继承关系¶
参数¶
API 文档¶
- class manim.ConvexHull3D(*points: Point3D, tolerance: float = 1e-05, **kwargs: Any)¶
基类:
PolyhedronA 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 入门第一件。
继承关系¶
参数¶
|
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)¶
基类:
VGroupA three-dimensional cube.
Parameters¶
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)
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)¶
基类:
SurfaceA 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 foruandvrespectively.
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.ndarrayPoints defining the
Cylinder.
Dodecahedron¶
十二面体:12 个五边形面的正多面体,Polyhedron 的预制实例。
继承关系¶
参数¶
API 文档¶
- class manim.Dodecahedron(edge_length: float = 1, **kwargs: Any)¶
基类:
PolyhedronA 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¶
三维空间中的小圆点:标记空间坐标用。
继承关系¶
参数¶
|
array([0., 0., 0.]),Point3D |
|---|---|
|
0.08,float |
|
ManimColor('#FFFFFF'),ParsableManimColor |
|
(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)¶
基类:
SphereA spherical dot.
Parameters¶
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 个三角面的正多面体。
继承关系¶
参数¶
API 文档¶
- class manim.Icosahedron(edge_length: float = 1, **kwargs: Any)¶
基类:
PolyhedronAn 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 构图骨架。
继承关系¶
参数¶
|
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)¶
基类:
CylinderA 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¶
- 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)¶
基类:
PolyhedronAn 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¶
通用多面体:顶点列表 + 面列表定义任意凸多面体,正多面体家族由此派生。
继承关系¶
参数¶
|
|
|---|---|
|
—,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] = {})¶
基类:
VGroupAn 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¶
棱柱:正多边形底面沿法向拉伸而成。
继承关系¶
参数¶
API 文档¶
- class manim.Prism(dimensions: Vector3DLike = [3, 2, 1], **kwargs: Any)¶
基类:
CubeA right rectangular prism (or rectangular cuboid). Defined by the length of each side in
[x, y, z]format.Parameters¶
- dimensions
Dimensions of the
Prismin[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)
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 文档¶
- 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)¶
基类:
SurfaceA three-dimensional sphere.
Parameters¶
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) andv_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)
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)¶
基类:
VGroupCreates a Parametric Surface using a checkerboard pattern.
Parameters¶
- func
The function defining the
Surface.- u_range
The range of the
uvariable:(u_min, u_max).- v_range
The range of the
vvariable:(v_min, v_max).- resolution
The number of samples taken of the
Surface. A tuple can be used to define different resolutions foruandvrespectively.- fill_color
The color of the
Surface. Ignored ifcheckerboard_colorsis 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
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)¶
基类:
PolyhedronA 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 图形祖先。
继承关系¶
参数¶
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)
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)¶
基类:
SurfaceA 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
uvariable:(u_min, u_max).- v_range
The range of the
vvariable:(v_min, v_max).- resolution
The number of samples taken of the
Torus. A tuple can be used to define different resolutions foruandvrespectively.
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)