VLnearestNeighbor

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - VL/Vertices/PC/Clouds
Introduced first in SolidGeometry 5.1, Creation date: 2021-12-10, Last change: 2025-09-15

returns the nearest points in VL1 to the points in VL2



See Also: nearestpair , nearestcluster , PLcorrelate , VLcorrelate

Example Illustration

 missing image of VLnearestNeighbor(VL1,VL2)

Syntax

nn=VLnearestNeighbor(VL1,VL2)

Input Parameter

VL1: Vertex list or Point List [m x 3]
VL2: Vertex list or Point List [n x 3]

Output Parameter

nn: Index in VL1 which is nearest to VL2 [n x 1]

Examples


VLnearestNeighbor(rand(10,2),rand(10,2))
VLnearestNeighbor(rand(10,3),rand(10,3))




Copyright 2021-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This algorithm is designed to find the nearest points in one vertex list (VL1) to the points in another vertex list (VL2). It is part of the SolidGeometry library and was introduced in version 5.1.

Input Parameters

Output Results

Algorithm Steps

  1. Check if VL1 and VL2 have two columns. If so, add a third column of zeros using the function VLaddz to convert them to 3D points.
  2. Suppress specific warnings related to triangulation in MATLAB.
  3. Create a triangulation object TR using the points in VL1.
  4. Use the nearestNeighbor function to find the nearest points in VL1 for each point in VL2. Store the indices in nn.
  5. Calculate the Euclidean distance nd between each point in VL2 and its nearest point in VL1 using the vecnormr function.
  6. Store the nearest points in VL1 corresponding to each point in VL2 in pp.
  7. If no output arguments are specified, plot the points and their connections using the SGfigure, VLplot, and lplot functions.

Example Usage

To find the nearest neighbors between two random sets of 2D or 3D points:

VLnearestNeighbor(rand(10,2),rand(10,2))
VLnearestNeighbor(rand(10,3),rand(10,3))
Algorithm explaination created using ChatGPT on 2025-08-19 07:09. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21