capytaine.new_meshes.meshes module¶
- class capytaine.new_meshes.meshes.Mesh(vertices: ndarray = None, faces: List[List[int]] | ndarray = None, name: str = None, *, auto_clean: bool = True, auto_check: bool = True)[source]¶
Bases:
objectMesh class for representing and manipulating 3D surface meshes.
- Parameters:
vertices (np.ndarray, optional) – Array of mesh vertices coordinates with shape (n_vertices, 3). Each row represents one vertex’s (x, y, z) coordinates.
faces (List[List[int]] or np.ndarray, optional) – Array of mesh connectivities for panels. Each row contains indices of vertices that form a face (triangles or quads).
name (str, optional) – Optional name for the mesh instance.
auto_clean (bool, optional) – Whether to automatically clean the mesh upon initialization. Defaults to True.
auto_check (bool, optional) – Whether to automatically check mesh quality upon initialization. Defaults to True.
- Variables:
vertices (np.ndarray) – Array of vertex coordinates with shape (n_vertices, 3).
name (str or None) – Name of the mesh instance.
- as_list_of_faces() List[List[List[float]]][source]¶
Convert the Mesh instance to a list of faces defined by vertex coordinates.
- Returns:
Each face is defined by a list of 3D coordinates. For example: [
[[x1, y1, z1], [x2, y2, z2], [x3, y3, z3]], [[x4, y4, z4], [x5, y5, z5], [x6, y6, z6]]
]
- Return type:
list of list of list of float
- extract_faces(faces_id, *, name=None) Mesh[source]¶
Extract a subset of faces by their indices and return a new Mesh instance.
- Parameters:
faces_id (array_like) – Indices of faces to extract.
name (str, optional) – A name for the new mesh
- Returns:
New mesh containing only the specified faces.
- Return type:
- property faces: ndarray¶
Face connectivity as quadrilateral array.
- Returns:
Array of shape (n_faces, 4) where triangular faces are padded by repeating the last vertex.
- Return type:
np.ndarray
Notes
This property converts all faces to a uniform quad representation for compatibility with libraries expecting fixed-width face arrays.
- property faces_areas: ndarray¶
Surface area of each face.
- Returns:
Array of shape (n_faces,) containing the area of each face.
- Return type:
np.ndarray
- property faces_centers: ndarray¶
Geometric centers of each face.
- Returns:
Array of shape (n_faces, 3) containing the center point of each face.
- Return type:
np.ndarray
- property faces_normals: ndarray¶
Normal vectors for each face.
- Returns:
Array of shape (n_faces, 3) containing unit normal vectors.
- Return type:
np.ndarray
- property faces_radiuses: ndarray¶
Radii of each face (circumradius or characteristic size).
- Returns:
Array of shape (n_faces,) containing the radius of each face.
- Return type:
np.ndarray
- property faces_vertices_centers: ndarray¶
Calculate the center of vertices that form the faces.
- Returns:
Array of shape (n_faces, 3) containing the centroid of each face’s vertices.
- Return type:
np.ndarray
- classmethod from_list_of_faces(list_faces, *, name=None, auto_clean=True, auto_check=True) Mesh[source]¶
Create a Mesh instance from a list of faces defined by vertex coordinates.
- Parameters:
list_faces (list of list of list of float) – Each face is defined by a list of 3D coordinates. For example: [
[[x1, y1, z1], [x2, y2, z2], [x3, y3, z3]], [[x4, y4, z4], [x5, y5, z5], [x6, y6, z6]]
]
name (str, optional) – A name for the new mesh.
auto_clean (bool, optional) – Whether to automatically clean the mesh upon initialization. Defaults to True.
auto_check (bool, optional) – Whether to automatically check mesh quality upon initialization. Defaults to True.
- Returns:
An instance of Mesh with: - unique vertices extracted from the input - faces defined as indices into the vertex array
- Return type:
- join_meshes(*, return_masks=False, name=None) Mesh[source]¶
Join two meshes and return a new Mesh instance.
- Parameters:
meshes (List[Mesh]) – Meshes to be joined
return_masks (bool, optional) – If True, additionally return a list of numpy masks establishing the origin of each face in the new mesh. (Default: False)
name (str, optional) – A name for the new object
- Returns:
New mesh containing vertices and faces from all meshes.
- Return type:
See also
__add__Implements the + operator for mesh joining.
- property nb_faces: int¶
Number of faces in the mesh.
- property nb_quads: int¶
Number of quadrilateral faces (4-vertex) in the mesh.
- property nb_triangles: int¶
Number of triangular faces (3-vertex) in the mesh.
- property nb_vertices: int¶
Number of vertices in the mesh.
- property quadrature_points: Tuple[ndarray, ndarray]¶
Quadrature points and weights for numerical integration.
- Returns:
(points, weights) where points has shape (n_faces, 1, 3) and weights has shape (n_faces, 1), using face centers and areas.
- Return type:
tuple[np.ndarray, np.ndarray]
- rotated_with_matrix(R, *, name=None) Mesh[source]¶
Return a new Mesh rotated using the provided 3×3 rotation matrix.
- rotated_x(angle: float, *, name=None) Mesh[source]¶
Return a new Mesh rotated around the x-axis using the provided rotation angle in radians
- rotated_y(angle: float, *, name=None) Mesh[source]¶
Return a new Mesh rotated around the y-axis using the provided rotation angle in radians
- rotated_z(angle: float, *, name=None) Mesh[source]¶
Return a new Mesh rotated around the z-axis using the provided rotation angle in radians
- show(*, backend=None, **kwargs)[source]¶
Visualize the mesh using the specified backend.
- Parameters:
backend (str, optional) – Visualization backend to use. Options are ‘pyvista’ or ‘matplotlib’. By default, try several until an installed one is found.
normal_vectors (bool, optional) – If True, display normal vectors on each face.
**kwargs – Additional keyword arguments passed to the visualization backend. See
visualization
- Returns:
Visualization object returned by the backend (e.g., matplotlib figure).
- Return type:
object
- Raises:
NotImplementedError – If the specified backend is not supported.
- show_matplotlib(**kwargs)[source]¶
Equivalent to show(backend=”matplotlib”). See also
show_matplotlib()
- show_pyvista(**kwargs)[source]¶
Equivalent to show(backend=”pyvista”). See also
show_pyvista()
- summary()[source]¶
Print a summary of the mesh properties.
Notes
Displays the mesh name, vertex count, face count, and bounding box.
- translated_x(dx: float, *, name=None) Mesh[source]¶
Return a new Mesh translated in the x-direction along dx.
- translated_y(dy: float, *, name=None) Mesh[source]¶
Return a new Mesh translated in the y-direction along dy.
- translated_z(dz: float, *, name=None) Mesh[source]¶
Return a new Mesh translated in the z-direction along dz.
- with_normal_vector_going_down(**kwargs) Mesh[source]¶
Ensure normal vectors point downward (negative z-direction).
- Returns:
Self if normals already point down, otherwise modifies face orientation.
- Return type:
Notes
Used for lid meshes to avoid irregular frequency issues by ensuring consistent normal vector direction.