多面体

限定名称: manim.mobject.three\_d.polyhedra.Polyhedron

class Polyhedron(vertex_coords, faces_list, faces_config={}, graph_config={})[source]

基类: VGroup

一个抽象的多面体类。

在此实现中,多面体由空间中的顶点坐标列表和面列表定义。此实现与标准多面体数据格式(OFF,对象文件格式)的实现方式相呼应。

参数:
  • 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

../_images/SquarePyramidScene-1.png
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)

在定义上述多面体时,我们首先定义了顶点的坐标。它们是正方形底部的角点(作为顶点列表中的前四个坐标)和顶点(列表中的最后一个坐标)。

接下来,我们定义多面体的面。金字塔的三角形表面是多边形,其角点是底部的两个相邻顶点和顶点处的顶点。因此,我们在面列表的前四个元素中定义这些表面。最后一个元素定义了金字塔的底部。

多面体的图和面在实例化后也可以直接访问和修改。它们分别存储在 graphfaces 属性中。

示例:PolyhedronSubMobjects

../_images/PolyhedronSubMobjects-1.png
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)

方法

create_faces

从面坐标列表创建面的VGroup。

extract_face_coords

提取图中顶点的坐标。

get_edges

创建循环成对元组的列表。

update_faces

属性

animate (动画)

用于动画化 self 的任何方法的应用。

animation_overrides (动画覆盖)

颜色

depth (深度)

mobject 的深度。

fill_color (填充颜色)

如果存在多种颜色(用于渐变),则返回第一种颜色

height (高度)

mobject 的高度。

n_points_per_curve (每条曲线的点数)

sheen_factor (光泽因子)

stroke_color (描边颜色)

width (宽度)

mobject 的宽度。

_original__init__(vertex_coords, faces_list, faces_config={}, graph_config={})

初始化自身。有关准确签名,请参阅 help(type(self))。

参数:
  • vertex_coords (list[list[float] | ndarray])

  • faces_list (list[list[int]])

  • faces_config (dict[str, str | int | float | bool])

  • graph_config (dict[str, str | int | float | bool])

create_faces(face_coords)[source]

从面坐标列表创建面的VGroup。

参数:

face_coords (list[list[list | ndarray]])

返回类型:

VGroup

extract_face_coords()[source]

提取图中顶点的坐标。用于更新面。

返回类型:

list[list[ndarray]]

get_edges(faces_list)[source]

创建循环成对元组的列表。

参数:

faces_list (list[list[int]])

返回类型:

list[tuple[int, int]]