# Get distance between two point from object surface

Hello, I’m trying to get distance between two points from geometry.

v1.distanceTo(v2)

This is not what I’m looking because this is a direct distance. I need the distance from the object surface. What is the best way to do it?

If you are looking for the closest point on a mesh to a given point, you need to iterate through all faces and then use Triangle.closestPointToPoint() . This will allow you to test each triangle and determine the point with the closest distance.

1 Like

To be clear I have two points

I’m trying to calculate the distance between them but I have to consider the geometry of the object. I get the points from clicking on the object (Raycaster).

I’m trying to calculate the distance between them but I have to consider the geometry of the object.

If you want the direct straight light distance between the points you can use the Vector3.distanceTo function.

If you’re actually interested in the shortest path between the points along the surface of the mesh that’s a much more difficult problem and one you won’t find an easy solution to directly in three.js or most graphics libraries. This is a twitter thread and link to research article I saw recently that discusses how to achieve that:

https://nmwsharp.com/research/flip-geodesics/

1 Like