trimesh.intersections module

intersections.py

Primarily mesh-plane intersections (slicing).

trimesh.intersections.mesh_multiplane(mesh, plane_origin, plane_normal, heights)

A utility function for slicing a mesh by multiple parallel planes which caches the dot product operation.

Parameters:
  • mesh (trimesh.Trimesh) – Geometry to be sliced by planes

  • plane_origin ((3,) float) – Point on a plane

  • plane_normal ((3,) float) – Normal vector of plane

  • heights ((m,) float) – Offset distances from plane to slice at: at height=0 it will be exactly on the passed plane.

Returns:

  • lines ((m,) sequence of (n, 2, 2) float) – Lines in space for m planes

  • to_3D ((m, 4, 4) float) – Transform to move each section back to 3D

  • face_index ((m,) sequence of (n,) int) – Indexes of mesh.faces for each segment

trimesh.intersections.mesh_plane(mesh, plane_normal, plane_origin, return_faces=False, local_faces=None, cached_dots=None)

Find a the intersections between a mesh and a plane, returning a set of line segments on that plane.

Parameters:
  • mesh (Trimesh object) – Source mesh to slice

  • plane_normal ((3,) float) – Normal vector of plane to intersect with mesh

  • plane_origin ((3,) float) – Point on plane to intersect with mesh

  • return_faces (bool) – If True return face index each line is from

  • local_faces (None or (m,) int) – Limit section to just these faces.

  • cached_dots ((n, 3) float) – If an external function has stored dot products pass them here to avoid recomputing.

Returns:

  • lines ((m, 2, 3) float) – List of 3D line segments in space.

  • face_index ((m,) int) – Index of mesh.faces for each line Only returned if return_faces was True

trimesh.intersections.plane_lines(plane_origin, plane_normal, endpoints, line_segments=True)

Calculate plane-line intersections

Parameters:
  • plane_origin ((3,) float) – Point on plane

  • plane_normal ((3,) float) – Plane normal vector

  • endpoints ((2, n, 3) float) – Points defining lines to be tested

  • line_segments (bool) – If True, only returns intersections as valid if vertices from endpoints are on different sides of the plane.

Returns:

  • intersections ((m, 3) float) – Cartesian intersection points

  • valid ((n, 3) bool) – Indicate whether a valid intersection exists for each input line segment

trimesh.intersections.planes_lines(plane_origins, plane_normals, line_origins, line_directions, return_distance=False, return_denom=False)

Given one line per plane find the intersection points.

Parameters:
  • plane_origins ((n,3) float) – Point on each plane

  • plane_normals ((n,3) float) – Normal vector of each plane

  • line_origins ((n,3) float) – Point at origin of each line

  • line_directions ((n,3) float) – Direction vector of each line

  • return_distance (bool) – Return distance from origin to point also

  • return_denom (bool) – Return denominator, so you can check for small values

Returns:

  • on_plane ((n,3) float) – Points on specified planes

  • valid ((n,) bool) – Did plane intersect line or not

  • distance ((n,) float) – [OPTIONAL] Distance from point

  • denom ((n,) float) – [OPTIONAL] Denominator

trimesh.intersections.slice_faces_plane(vertices, faces, plane_normal, plane_origin, uv=None, face_index=None, cached_dots=None)

Slice a mesh (given as a set of faces and vertices) with a plane, returning a new mesh (again as a set of faces and vertices) that is the portion of the original mesh to the positive normal side of the plane.

Parameters:
  • vertices ((n, 3) float) – Vertices of source mesh to slice

  • faces ((n, 3) int) – Faces of source mesh to slice

  • plane_normal ((3,) float) – Normal vector of plane to intersect with mesh

  • plane_origin ((3,) float) – Point on plane to intersect with mesh

  • uv ((n, 2) float, optional) – UV coordinates of source mesh to slice

  • face_index (((m,) int)) – Indexes of faces to slice. When no mask is provided, the default is to slice all faces.

  • cached_dots ((n, 3) float) – If an external function has stored dot products pass them here to avoid recomputing

Returns:

  • new_vertices ((n, 3) float) – Vertices of sliced mesh

  • new_faces ((n, 3) int) – Faces of sliced mesh

  • new_uv ((n, 2) int or None) – UV coordinates of sliced mesh

trimesh.intersections.slice_mesh_plane(mesh, plane_normal, plane_origin, face_index=None, cap=False, engine=None, **kwargs)

Slice a mesh with a plane returning a new mesh that is the portion of the original mesh to the positive normal side of the plane.

Parameters:
  • mesh (Trimesh object) – Source mesh to slice

  • plane_normal ((3,) float) – Normal vector of plane to intersect with mesh

  • plane_origin ((3,) float) – Point on plane to intersect with mesh

  • cap (bool) – If True, cap the result with a triangulated polygon

  • face_index (((m,) int)) – Indexes of mesh.faces to slice. When no mask is provided, the default is to slice all faces.

  • cached_dots ((n, 3) float) – If an external function has stored dot products pass them here to avoid recomputing

  • engine (None or str) – Triangulation engine passed to triangulate_polygon

  • kwargs (dict) – Passed to the newly created sliced mesh

Returns:

new_mesh – Sliced mesh

Return type:

Trimesh object