nearestvertex
Index of the polyshape vertex closest to each query point.
Category: Mathematics > Computational Geometry
Syntax
vid = nearestvertex(pshape, xq, yq)
For each query point, the index of the nearest vertex.
Description
The distance is measured to the polygon's vertices, not to its edges, so a point near the middle of a long edge may be matched to a distant corner. For distance to edges, test isinterior or buffer the shape with polybuffer.
Input arguments
pshape- A
polyshapeobject. xq, yq- Coordinates of the query points.
Output arguments
vid- Column vector of vertex indices.
Example
Nearest corners of a rectangle
P = polyshape([0 4 4 0], [0 0 3 3]);
vid = nearestvertex(P, [3.9 0.1], [2.9 0.2])
Output
vid = 2×1
3
1