-1

I'm using trimesh to find the closest point on a mesh to a given point,

closest_vertex, d, face_id = trimesh.proximity.closest_point(mesh, [[-5,100,0]])

That's my code for that bit I get an point back from this code and it displays fine on a graph as well. However when I look at the stl file to figure out the point index, the point does not exist.

Any help would be awesome!

I expect to find this point in the stl as after all it still is returning the closest point.

273K
  • 29,503
  • 10
  • 41
  • 64
  • Read it carefully: [tag:STL] Do NOT use for questions about 3D CAD model. Use [stl-format] instead. – 273K Jul 30 '23 at 17:02

1 Answers1

0

As per documentation :

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

So it is finding the closest point on your trimesh surface, not the closest vertex. This is why you are not finding the point in your STL file.

To find the nearest vertex, you'll probably need to write a small function for this :

import numpy as np

def find_closest_vertex(mesh, poi):
    idx = np.argmin(np.linalg.norm(mesh.vertices-poi, 2))
    return mesh.vertices[idx, :]
Hoodlum
  • 950
  • 2
  • 13
  • Hey, so that gives me alot of clarity but also arises me a question? So if I had to find the closest point would that be a possibility? – Vishnu Panda Jul 30 '23 at 22:33
  • yes, that would be a possibility. I'm not aware of any function in the trimesh library that would do this, but the code i included in the answer should work. – Hoodlum Jul 31 '23 at 06:42
  • also, if this answers your question, please mark the answer as 'accepted'. It helps with the housekeeping of the site :) – Hoodlum Jul 31 '23 at 06:43