Polyhedron#
Qualified name: manim.mobject.three\_d.polyhedra.Polyhedron
- class Polyhedron(vertex_coords, faces_list, faces_config={}, graph_config={})[source]#
Bases:
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 (list[list[float] | np.ndarray]) – 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 (list[list[int]]) – A list of faces. Each face is a sublist containing the indices of the vertices that form the corners of that face.
faces_config (dict[str, str | int | float | bool]) – Configuration for the polygons representing the faces of the polyhedron.
graph_config (dict[str, str | int | float | bool]) – 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.
Example: 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)
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.
Example: 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)
Methods
Creates VGroup of faces from a list of face coordinates.
Extracts the coordinates of the vertices in the graph.
Creates list of cyclic pairwise tuples.
update_faces
Attributes
animate
Used to animate the application of any method of
self
.animation_overrides
color
depth
The depth of the mobject.
fill_color
If there are multiple colors (for gradient) this returns the first one
height
The height of the mobject.
n_points_per_curve
sheen_factor
stroke_color
width
The width of the mobject.
- create_faces(face_coords)[source]#
Creates VGroup of faces from a list of face coordinates.
- Parameters
face_coords (list[list[list | np.ndarray]]) –
- Return type