多面体¶
限定名称: manim.mobject.three\_d.polyhedra.Polyhedron
- class Polyhedron(vertex_coords, faces_list, faces_config={}, graph_config={})[source]¶
基础类:
VGroup一个抽象的多面体类。
在这个实现中,多面体是通过空间中的顶点坐标列表和面列表来定义的。这个实现反映了标准多面体数据格式(OFF,对象文件格式)的实现。
- Parameters:
vertex_coords (list[list[float] | np.ndarray]) – 多面体中对应顶点的坐标列表。每个坐标将对应一个顶点。顶点使用Python的常规索引进行索引。
faces_list (list[list[int]]) – 一个面的列表。每个面是一个子列表,包含构成该面角的顶点的索引。
faces_config (dict[str, str | int | float | bool]) – 用于表示多面体面的多边形的配置。
graph_config (dict[str, str | int | float | bool]) – 包含多面体顶点和边的图的配置。
示例
要了解如何创建自定义多面体,让我们使用一个相当简单的例子——一个方形金字塔。
示例:SquarePyramidScene ¶
from manim import * 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)
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)在定义上述多面体时,我们首先定义了顶点的坐标。 这些是方形底座的角,作为顶点列表中的前四个坐标给出, 以及顶点,列表中的最后一个坐标。
接下来,我们定义多面体的面。金字塔的三角形面是带有两个相邻顶点在底部和顶点在顶点的多边形。因此,我们在面列表的前四个元素中定义这些面。最后一个元素定义了金字塔的底部。
多面体的图和面也可以在实例化后直接访问和修改。 它们分别存储在graph和faces属性中。
示例:PolyhedronSubMobjects ¶
from manim import * 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)
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)方法
从面坐标列表中创建面的VGroup。
提取图中顶点的坐标。
创建循环成对元组的列表。
update_faces属性
animate用于动画化
self的任何方法的应用。animation_overridescolordepthmobject的深度。
fill_color如果有多种颜色(用于渐变),则返回第一个颜色
heightmobject的高度。
n_points_per_curvesheen_factorstroke_colorwidthmobject的宽度。
- _original__init__(vertex_coords, faces_list, faces_config={}, graph_config={})¶
初始化自身。有关准确的签名,请参阅 help(type(self))。
- Parameters:
vertex_coords (列表[列表[浮点数] | ndarray])
faces_list (列表[列表[整数]])
faces_config (dict[str, str | int | float | bool])
graph_config (字典[字符串, 字符串 | 整数 | 浮点数 | 布尔值])