user27665
user27665

Reputation: 683

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

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.

Upvotes: 1

Views: 478

Answers (1)

blunova
blunova

Reputation: 2532

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]

Upvotes: 1

Related Questions