trimesh.proximity¶
proximity.py¶
Query mesh point proximity.
Classes:

Proximity queries for the current mesh. 
Functions:

Given a mesh and a list of points find the closest point on any triangle. 

Given a mesh and a list of points find the closest point on any triangle. 

Find the lengths of the longest rays which do not intersect the mesh cast from a list of points in the provided directions. 

Find the center and radius of the sphere which is tangent to the mesh at the given point and at least one more point with no nontangential intersections with the mesh. 

For each point find nearby faces relatively quickly. 

Find the signed distance from a mesh to a list of points. 

Find the thickness of the mesh at the given points. 

class
trimesh.proximity.
ProximityQuery
(mesh)¶ Bases:
object
Proximity queries for the current mesh.
Methods:
on_surface
(**kwargs)Given list of points, for each point find the closest point on any triangle of the mesh.
signed_distance
(points)Find the signed distance from a mesh to a list of points.
vertex
(points)Given a set of points, return the closest vertex index to each point

on_surface
(**kwargs)¶ Given list of points, for each point find the closest point on any triangle of the mesh.
 Parameters
points ((m,3) float, points in space) –
 Returns
closest ((m, 3) float) – Closest point on triangles for each point
distance ((m,) float) – Distance to surface
triangle_id ((m,) int) – Index of closest triangle for each point.

signed_distance
(points)¶ Find the signed distance from a mesh to a list of points.
Points OUTSIDE the mesh will have NEGATIVE distance
Points within tol.merge of the surface will have POSITIVE distance
Points INSIDE the mesh will have POSITIVE distance
 Parameters
points ((n, 3) float) – Points in space
 Returns
signed_distance – Signed distance from point to mesh.
 Return type
(n, 3) float

vertex
(points)¶ Given a set of points, return the closest vertex index to each point
 Parameters
points ((n, 3) float) – Points in space
 Returns
distance ((n,) float) – Distance from source point to vertex.
vertex_id ((n,) int) – Index of mesh.vertices for closest vertex.


trimesh.proximity.
closest_point
(mesh, points)¶ Given a mesh and a list of points find the closest point on any triangle.
 Parameters
mesh (trimesh.Trimesh) – Mesh to query
points ((m, 3) float) – Points in space
 Returns
closest ((m, 3) float) – Closest point on triangles for each point
distance ((m,) float) – Distance to mesh.
triangle_id ((m,) int) – Index of triangle containing closest point

trimesh.proximity.
closest_point_naive
(mesh, points)¶ Given a mesh and a list of points find the closest point on any triangle.
Does this by constructing a very large intermediate array and comparing every point to every triangle.
 Parameters
mesh (Trimesh) – Takes mesh to have same interfaces as closest_point
points ((m, 3) float) – Points in space
 Returns
closest ((m, 3) float) – Closest point on triangles for each point
distance ((m,) float) – Distances between point and triangle
triangle_id ((m,) int) – Index of triangle containing closest point

trimesh.proximity.
longest_ray
(mesh, points, directions)¶ Find the lengths of the longest rays which do not intersect the mesh cast from a list of points in the provided directions.
 Parameters
points ((n, 3) float) – Points in space.
directions ((n, 3) float) – Directions of rays.
 Returns
signed_distance – Length of rays.
 Return type
(n,) float

trimesh.proximity.
max_tangent_sphere
(mesh, points, inwards=True, normals=None, threshold=1e06, max_iter=100)¶ Find the center and radius of the sphere which is tangent to the mesh at the given point and at least one more point with no nontangential intersections with the mesh.
Masatomo Inui, Nobuyuki Umezu & Ryohei Shimane (2016) Shrinking sphere: A parallel algorithm for computing the thickness of 3D objects, ComputerAided Design and Applications, 13:2, 199207, DOI: 10.1080/16864360.2015.1084186
 Parameters
points ((n, 3) float) – Points in space.
inwards (bool) – Whether to have the sphere inside or outside the mesh.
normals ((n, 3) float or None) – Normals of the mesh at the given points if is None computed automatically.
 Returns
centers ((n,3) float) – Centers of spheres
radii ((n,) float) – Radii of spheres

trimesh.proximity.
nearby_faces
(mesh, points)¶ For each point find nearby faces relatively quickly.
The closest point on the mesh to the queried point is guaranteed to be on one of the faces listed.
Does this by finding the nearest vertex on the mesh to each point, and then returns all the faces that intersect the axis aligned bounding box centered at the queried point and extending to the nearest vertex.
 Parameters
mesh (trimesh.Trimesh) – Mesh to query.
points ((n, 3) float) – Points in space
 Returns
candidates – Sequence of indexes for mesh.faces
 Return type
(points,) int

trimesh.proximity.
signed_distance
(mesh, points)¶ Find the signed distance from a mesh to a list of points.
Points OUTSIDE the mesh will have NEGATIVE distance
Points within tol.merge of the surface will have POSITIVE distance
Points INSIDE the mesh will have POSITIVE distance
 Parameters
mesh (trimesh.Trimesh) – Mesh to query.
points ((n, 3) float) – Points in space
 Returns
signed_distance – Signed distance from point to mesh
 Return type
(n, 3) float

trimesh.proximity.
thickness
(mesh, points, exterior=False, normals=None, method='max_sphere')¶ Find the thickness of the mesh at the given points.
 Parameters
points ((n, 3) float) – Points in space
exterior (bool) – Whether to compute the exterior thickness (a.k.a. reach)
normals ((n, 3) float) – Normals of the mesh at the given points If is None computed automatically.
method (string) – One of ‘max_sphere’ or ‘ray’
 Returns
thickness – Thickness at given points.
 Return type
(n,) float