In trimesh, how to get the triangle id given a point location and the mesh?

240 views Asked by At

Using trimesh, I need to find the triangle id for a point given a triangular mesh. The point lies on an edge of the mesh or it may be a triangle vertex.

import trimesh
import numpy as np

mesh = trimesh.load('mesh.off')
triangles = mesh.triangles

pt= [2.7605, 2.996054, 0.263109]

# Find the triangle id for the point pt
# ???

My question is how to get the triangle id for a point given a triangular mesh using trimesh.

1

There are 1 answers

1
blunova On

Using trimesh you can find the ID of the triangle where the point lies with the following code:

mesh = trimesh.load('mesh.off')
point = np.array([2.7605, 2.996054, 0.263109]).reshape(1, -1)
proximity_query = ProximityQuery(mesh)
id_ = proximity_query.on_surface(point)[2]