File: closestnode.m

package info (click to toggle)
octave-brain2mesh 0.7.9-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 11,736 kB
  • sloc: makefile: 54
file content (24 lines) | stat: -rw-r--r-- 678 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function [idx, dist]=closestnode(node,p)
%
% [idx, dist]=closestnode(node,p)
%
% Find the closest point in a node list and return its index

% author: Qianqian Fang (q.fang at neu.edu)
%
% input:
%    node: each row is an N-D node coordinate
%    p: a given position in the same space
%
% output:
%    idx: the index of the position in the node list that has the shortest
%         Euclidean distance to the position p
%    dist: the distances between p and each node
%
%
% -- this function is part of brain2mesh toolbox (http://mcx.space/brain2mesh)
%    License: GPL v3 or later, see LICENSE.txt for details
%

dd=node-repmat(p,size(node,1),1);
[dist,idx]=min(sum(dd.*dd,2));