nearestNeighbor
Nearest vertex of a triangulation or alpha shape to each query point.
Category: Mathematics > Computational Geometry
Syntax
k = nearestNeighbor(TR, P)
Index of the closest vertex of the triangulation for each row of P.
[k, d] = nearestNeighbor(TR, P)
Also returns the distances.
k = nearestNeighbor(shp, xq, yq)
For an alphaShape, the closest of its points to the query points.
Description
The answer is always a vertex of the object, never a point on an edge or inside a face. The search uses Euclidean distance. For plain arrays of points use dsearchn, which works the same way.
Input arguments
TR- A
triangulation,delaunayTriangulationorDelaunayTriobject. P- Query points, one per row.
shp, xq, yq- An
alphaShapeand the coordinates of the query points.
Output arguments
k- Indices of the nearest points, a column vector.
d- Euclidean distances to those points, a column vector.
Example
Closest vertices
x = [0 1 1 0 0.5]';
y = [0 0 1 1 0.5]';
DT = delaunayTriangulation(x, y);
[k, d] = nearestNeighbor(DT, [0.1 0.1; 0.9 0.9])
Output
k = 2×1
1
3
d = 2×1
0.1414
0.1414