# Surface measurement - help

working on measuring the distance of two points along the surface of an object. gotten to the part where i can calculate the distance between two points. however if the surface is not flat, that does not really work.

This is where i am right now. the line seems to be hovering over the surface… any advice?

you need to use some path finding lib. maybe like donmccurdy’s lib - there instead of navigation mesh you would need to find the path on your actual mesh and sum the path segment lengths up. I have also simpler and faster path finder here but unlike donmccurdy’s this one only calculates the path along the edges so the mesh needs to be dense enough for this method to be accurate.

1 Like

Afaik there’s nothing out of the box to support this with any kind of exactness but there are effective algorithms out there for measuring this that you can implement. See here:

1 Like

looking at the pdf linked from your link, I dont think “geodesics” would be a good idea for finding a distance:

That image specifically is showing retaining the line wrapping around the cylinder 5 times and optimizing the path. I believe you need to start with a reasonable initial path but if you want a path pulled “taut” along the surface this is the kind of thing you need.

If this is just more of a nice-to-have helper and only for surfaces where the user picks a reasonable connected area without holes,gaps or too heavy concave surfaces you could so do this by plotting sample points with a raycaster from start to end.

Positioning the raycaster at the bounding sphere radius displaced and pointing at the direction of the normal of A lerped to B the closer the sample is (bounding sphere radius as max, but pick the distance rather by a initial inverted direction raycast from the start, in case it’s inside something), for the sample distance you could initially look for the average triangle size the mesh has. It’s still not 100% accurate depending on the step size but probably good enough depending on the usease.

However, If it’s about real physical objects you wouldn’t get the accurate real world distance anyway, since a triangulated mesh won’t precisely result in the same distance as an actual round surface.

If you need a full and more proper/robust solution that works around corners/backside of mesh consistently etc you need navigation mesh path finding.

2 Likes