trimesh.proximity module¶
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)
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, list of points in space) –
 Returns
signed_distance
 Return type
(n,3) float, signed distance from point to mesh

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


trimesh.proximity.
closest_point
(mesh, points)¶ Given a mesh and a list of points, find the closest point on any triangle.
 Parameters
mesh (Trimesh object) –
points ((m,3) float, points in space) –
 Returns
closest ((m,3) float, closest point on triangles for each point)
distance ((m,) float, distance)
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, list of points in space) –
directions ((n,3) float, directions of rays) –
 Returns
signed_distance
 Return type
(n,) float, length of rays

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, list of points in space) –
inwards (bool, whether to have the sphere inside or outside the mesh) –
normals ((n,3) float, normals of the mesh at the given points) – None, compute this 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 object) –
points ((n,3) float , points in space) –
 Returns
candidates
 Return type
(points,) int, sequence of indexes for mesh.faces

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 object) –
points ((n,3) float, list of points in space) –
 Returns
signed_distance
 Return type
(n,3) float, signed distance from point to mesh

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, list of 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) – None, compute this automatically.
method (string, one of 'max_sphere' or 'ray') –
 Returns
thickness
 Return type
(n,) float, thickness