Closest_point_on_mesh - closest point from one mesh to another


I have 2 meshes and I would like to get the closest point from one vertex in the first mesh to the second mesh.

I did it by taking the coordinate of the vertex in the source mesh:
vertex_index = 0
point =[vertex_index].co

Then, I define the target_obj to be the active and called closest_point_on_mesh to find the closest point to that point: = target_obj
closest_point = bpy.context.object.closest_point_on_mesh(point)

But it seems that it’s not the correct one, I see it by selecting the 2 points.
I think that it’s related to the following statement:

Find the nearest point in object space

But I don’t understand how to fix it.

Does anyone has some insight about it?

Closest Point on Tri:
KD Tree:

This is the way!

1 Like