Skip to content

flex_rf.tidy3d.TriangleMesh

Type: class Base(s): Geometry, ABC

Custom surface geometry given by a triangle mesh, as in the STL file format.

vertices = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]])
faces = np.array([[1, 2, 3], [0, 3, 2], [0, 1, 3], [0, 2, 1]])
stl_geom = TriangleMesh.from_vertices_faces(vertices, faces)
mesh_dataset [TriangleMeshDataset | None] = None

Surface mesh data.

bounds()

Returns bounding box min and max coordinates.

fill_holes()

Try to fill holes in the mesh. Can be used to repair non-watertight meshes.

fix_normals()

Try to fix normals to be consistent and outward-facing.

fix_winding()

Try to fix winding in the mesh.

from_height_function(axis: Ax, direction: Literal['-', '+'], base: float, center: tuple[float, float], size: tuple[float, float], grid_size: tuple[int, int], height_func: Callable[[np.ndarray, np.ndarray], np.ndarray])

Construct a TriangleMesh object from analytical expression of height function. The height function should be vectorized to accept 2D meshgrid arrays.

from_height_grid(axis: Ax, direction: Literal['-', '+'], base: float, grid: tuple[np.ndarray, np.ndarray], height: NDArray)

Construct a TriangleMesh object from grid based height information.

from_stl(filename: str, scale: float = 1.0, origin: tuple[float, float, float] = (0, 0, 0), solid_index: int | None = None, **kwargs: Any)

Load a TriangleMesh directly from an STL file. The solid_index parameter can be used to select a single solid from the file. Otherwise, if the file contains a single solid, it will be loaded as a TriangleMesh; if the file contains multiple solids, they will all be loaded as a GeometryGroup.

from_triangles(triangles: NDArray)

Create a TriangleMesh from a numpy array containing the triangles of a surface mesh.

from_trimesh(mesh: Trimesh)

Create a TriangleMesh from a trimesh.Trimesh object.

from_vertices_faces(vertices: NDArray, faces: NDArray)

Create a TriangleMesh from numpy arrays containing the data of a surface mesh. The first array contains the vertices, and the second array contains faces formed from triples of the vertices.

inside(x: NDArray, y: NDArray, z: NDArray)

For input arrays x, y, z of arbitrary but identical shape, return an array with the same shape which is True for every point in zip(x, y, z) that is inside the volume of the Geometry, and False otherwise.

intersections_plane(x: float | None = None, y: float | None = None, z: float | None = None, cleanup: bool = True, quad_segs: int | None = None, section_tolerance_2d: bool = False)

Returns list of shapely geometries at plane specified by one non-None value of x,y,z.

intersections_tilted_plane(normal: Coordinate, origin: Coordinate, to_2D: MatrixReal4x4, cleanup: bool = True, quad_segs: int | None = None, section_tolerance_2d: bool = False)

Return a list of shapely geometries at the plane specified by normal and origin.

plot(x: float | None = None, y: float | None = None, z: float | None = None, ax: Ax = None, **patch_kwargs: Any)

Plot geometry cross section at single (x,y,z) coordinate.

subdivide_faces(vertices: NDArray, faces: NDArray)

Uniformly subdivide each triangular face by inserting edge midpoints.

to_stl(filename: PathLike, *, binary: bool = True)

Export this TriangleMesh to an STL file.

triangles()

The triangles of the surface mesh as an np.ndarray.

trimesh()

A trimesh.Trimesh object representing the custom surface mesh geometry.