pythagoras.r3.mesh module¶
- class pythagoras.r3.mesh.Face(v1: tuple[float, float, float], v2: tuple[float, float, float], v3: tuple[float, float, float], shaded: bool = True, zord: int = 0)[source]¶
Bases:
PObject3DTriangle in \(\mathbf R^3\) which is meant to belong to a mesh.
- Variables:
v1 (tuple[float, float, float]) – First vertex.
v2 (tuple[float, float, float]) – Second vertex.
v3 (tuple[float, float, float]) – Third vertex.
n (pythagoras.r3.vector.Vector3D) – Normal vector. It follows the orientation given by
v1-v2-v3.shaded (bool) – Whether to apply shading to the triangle.
- property centroid: tuple[float, float, float]¶
- shaded: bool¶
- svg(camera: Camera3D, frustum: float, width: float, height: float, scale: float, lights: list[tuple[tuple[float, float, float], float]], *args: POProperty) str[source]¶
Compiles the 3D object into SVG commands.
- Returns:
The corresponding SVG code.
- tikz(camera: Camera3D, frustum: float, lights: list[tuple[tuple[float, float, float], float]], *args: POProperty) str[source]¶
Compiles the 3D object into a sequence of TikZ instructions.
- Returns:
The resulting TikZ code.
- v1: tuple[float, float, float]¶
- v2: tuple[float, float, float]¶
- v3: tuple[float, float, float]¶
- class pythagoras.r3.mesh.Mesh(triangles: Iterable[tuple[Face, tuple[POProperty, ...]]], vertices: Iterable[tuple[float, float, float]] | None = None, backface_culling: bool = False, zord: int = 0)[source]¶
Bases:
PObject3DThree-dimensional mesh, represented as a collection of triangles. Vertices are also stored for efficient retrieval.
- Variables:
triangles (tuple[tuple[pythagoras.r3.mesh.Face, tuple[pythagoras.pobject.POProperty, ...]], ...]) – Triangles that make up the mesh, together with their properties.
vertices (set[tuple[float, float, float]]) – Vertices of the mesh.
backface_culling (bool) – Whether to apply back-face culling to the mesh. When set to true, faces with normal vectors that do not face the camera are not rendered. This is not recommended for figures that are not closed, and in which its back can be seen. It is disabled by default, unless you are importing your model from an OBJ file.
- backface_culling: bool¶
- classmethod from_obj(obj: str, shaded: bool = True, backface_culling: bool = True, zord: int = 0, *args: POProperty) Self[source]¶
Constructs a mesh from Wavefront OBJ-formatted string. It only supports the
vandfcommands, the remaining ones are ignored when encountered.- Parameters:
obj – 3D OBJ model.
shaded – Whether to calculate face normals for shading.
backface_culling – Whether to apply back-face culling to the mesh. See
Mesh.backface_culling.zord – Rendering priority within a
Canvas3Dcontext.args – Properties to apply globally to the mesh.
- Returns:
A
Meshinstance.
- classmethod parametric(phi: Callable[[float, float], tuple[float, float, float]], u_range: tuple[float, float], v_range: tuple[float, float], dp: tuple[float, float] = (0, 0), shaded: bool = False, backface_culling: bool = False, zord: int = 0, *args: POProperty) Self[source]¶
Constructs a mesh from a parametric surface, described by a function \(\phi: \mathbf R^2 \longrightarrow \mathbf R^3\).
- Parameters:
phi – Function that parametrizes the curve.
u_range – Domain of the first variable.
v_range – Domain of the second variable.
dp – Increments in both directions. If any of the entries is less than or equal to zero, its domain is divided into 100 subintervals.
shaded – Whether to apply shading to the surface.
backface_culling – Whether to apply back-face culling to the mesh. See
Mesh.backface_culling.zord – Rendering priority.
args – Attributes for all the triangles.
- Returns:
A
Meshinstance with the shape given by \(\phi\).
- svg(camera: Camera3D, frustum: float, width: float, height: float, scale: float, lights: list[tuple[tuple[float, float, float], float]], *args: POProperty) str[source]¶
Compiles the 3D object into SVG commands.
- Returns:
The corresponding SVG code.
- tikz(camera: Camera3D, frustum: float, lights: list[tuple[tuple[float, float, float], float]], *args: POProperty) str[source]¶
Compiles the 3D object into a sequence of TikZ instructions.
- Returns:
The resulting TikZ code.
- translate(translation: tuple[float, float, float]) None[source]¶
Translates the mesh in some direction in space.
- Parameters:
translation – Coordinates of the translation vector.
- triangles: tuple[tuple[Face, tuple[POProperty, ...]], ...]¶
- vertices: set[tuple[float, float, float]]¶