Skip to content

nearestNeighbor

geometry · scripts/geometry/nearestNeighbor.m

: ID = nearestNeighbor (TR, P)
: ID = nearestNeighbor (TR, x, y)
: ID = nearestNeighbor (TR, x, y, z)
: [ID, d] = nearestNeighbor (…)

Vertex closest to each query point (MATLAB triangulation / alphaShape).

TR is a triangulation-like struct with a Points field (also accepts delaunayTriangulation and alphaShape shims). Query points are rows of P, or separate coordinate columns. ID holds 1-based row indices into TR.Points; d is Euclidean distance. Ties go to the highest index on small clouds (MATLAB R2026a triangulation). Large point sets use the engine __dsearchn__ nearest-point search.