DISTANCEPOINTMESH Shortest distance between a (3D) point and a triangle mesh. DIST = distancePointMesh(POINT, VERTICES, FACES) Returns the shortest distance between the query point POINT and the triangular mesh defined by the set of vertex coordinates VERTICES and the set of faces FACES. VERTICES is a NV-by-3 array, and FACES is a NF-by-3 array of vertex indices. If FACES is NF-by-4 array, it is converted to a (NF*2)-by-3 array. [DIST, PROJ] = distancePointMesh(...) Also returns the projection of the query point on the triangular mesh. ... = distancePointMesh(..., 'algorithm', ALGO) Allows to choose the type of algorithm. Options are: * sequential: process each face sequentially, using the function distancePointTriangle3d * vectorized: vectorized algorithm, usually faster for large number of faces * auto: (default) automatically choose the most appropriate between sequential and vectorized. Example [V, F] = torusMesh(); F2 = triangulateFaces(F); P = [10 20 30]; [D, PROJ] = distancePointMesh(P, V, F2); figure; drawMesh(V, F) view(3); axis equal; lighting gouraud; light; drawPoint3d(P); drawPoint3d(PROJ, 'm*'); drawEdge3d([P PROJ], 'linewidth', 2, 'color', 'b'); See also distancePointTriangle3d References * "Distance Between Point and Triangle in 3D", David Eberly (1999) https://www.geometrictools.com/Documentation/DistancePoint3Triangle3.pdf * Distance between a point and a triangle in 3d, by Gwendolyn Fischer. * Distance Between Point and Triangulated Surface, by Daniel Frisch.
Package: matgeom