GPLnearestpoint

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - VM/Voxels
Introduced first in SolidGeometry 4.7, Creation date: 2019-07-25, Last change: 2025-09-14

returns the nearest point index within a Grid point list

Description

d=vecnormr(GPL-p); i=find(d==min(d)); i=i(1);


See Also: GPLdistancetoCPL

Example Illustration

 missing image of GPLnearestpoint(GPL,p)

Syntax

[i,p]=GPLnearestpoint(GPL,[p])

Input Parameter

GPL: Grid Point List
p: point to check

Output Parameter

i: nearest point
p: point coordinates

Examples


CPL=CPLsample(13); GPLdistancetoCPL(CPL,.1,'','','','',true);
[GPL,k]=GPLdistancetoCPL(CPL,.1,'','','','',true);
GPLnearestpoint(GPL)




Copyright 2019-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 function, GPLnearestpoint, is designed to find the nearest point in a Grid Point List (GPL) to a specified point p. It is part of the SolidGeometry library and was introduced in version 4.7.

Input Parameters

Output Results

Algorithm Steps

  1. The function begins by retrieving the input parameters using getfuncparams. If p is not provided, it defaults to an empty array, and k defaults to the size of the GPL.
  2. If p is empty, the function uses ginput to allow the user to select a point graphically. A flag sho is set to true to indicate that a point was selected graphically.
  3. The function calculates the Euclidean distance from each point in the GPL to the point p using vecnormr.
  4. It finds the index i of the point in the GPL that has the minimum distance to p. If there are multiple points with the same minimum distance, it selects the first one.
  5. If no output arguments are specified, and if a point was selected graphically, the function plots the nearest point using PLplot and then deletes the plot after a short pause.

This function is useful for applications where determining the closest point in a set of grid points to a given point is necessary, such as in spatial analysis or computer graphics.

Algorithm explaination created using ChatGPT on 2025-08-19 00:01. (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