Home > vbmeg > functions > common > coordinate > vb_find_min_distance_2d.m

vb_find_min_distance_2d

PURPOSE ^

Find min distance point in y from x

SYNOPSIS ^

function [yindx, yout, ddmin] = vb_find_min_distance_2d(x,y)

DESCRIPTION ^

 Find min distance point in y from x
 [yindx, yout, ddmin] = vb_find_min_distance_2d(x,y)
 --- Input
 x : set of 2D coordinate (N x 2)
 y : set of 2D coordinate (M x 2)
 --- Output
 yindx(n)     : min distance point index from x(n,1:2)
 yout(n,1:2)  : min distance point in y from x(n,1:2)
 ddmin(n)     : min distance from x(n,1:2)

  rhayashi  2007-5-15

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    [yindx, yout, ddmin] = vb_find_min_distance_2d(x,y)
0002 % Find min distance point in y from x
0003 % [yindx, yout, ddmin] = vb_find_min_distance_2d(x,y)
0004 % --- Input
0005 % x : set of 2D coordinate (N x 2)
0006 % y : set of 2D coordinate (M x 2)
0007 % --- Output
0008 % yindx(n)     : min distance point index from x(n,1:2)
0009 % yout(n,1:2)  : min distance point in y from x(n,1:2)
0010 % ddmin(n)     : min distance from x(n,1:2)
0011 %
0012 %  rhayashi  2007-5-15
0013 %
0014 % Copyright (C) 2011, ATR All Rights Reserved.
0015 % License : New BSD License(see VBMEG_LICENSE.txt)
0016 
0017 N  = size(x,1);
0018 M  = size(y,1);
0019 
0020 dd    = zeros(M,1);
0021 ddmin = zeros(N,1);
0022 yindx = zeros(N,1);
0023 
0024 for n=1:N
0025     xn = x(n,:);
0026     dd = (y(:,1) - xn(1)).^2 ...
0027        + (y(:,2) - xn(2)).^2;
0028        
0029     [ddmin(n) ,yindx(n)] = min(dd);
0030 end;
0031 
0032 if nargout == 1, return; end;
0033 
0034 yout = y(yindx,:);
0035 
0036 if nargout == 3, ddmin = sqrt(ddmin); end;

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005