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
- GPL: A matrix representing the Grid Point List, where each row corresponds to a point in space.
- p: (Optional) A specific point to which the nearest point in the GPL is to be found. If not provided, the function will prompt the user to select a point graphically.
Output Results
- i: The index of the nearest point in the GPL to the point
p
.
- p: The coordinates of the point
p
.
Algorithm Steps
- 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.
- 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.
- The function calculates the Euclidean distance from each point in the GPL to the point
p
using vecnormr
.
- 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.
- 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