Home > fvcom_prepro > find_nearest_pt.m

find_nearest_pt

PURPOSE ^

Find nearest point in Mesh structure to (x,y)

SYNOPSIS ^

function [Point,Distance] = find_nearest_pt(xloc,yloc,Mobj)

DESCRIPTION ^

 Find nearest point in Mesh structure to (x,y) 

 function [Point,Distance] = find_nearest_pt(xloc,yloc,Mobj) 

 DESCRIPTION:
    Find nearest point to (xloc,yloc) in the domain of Mobj
    using native coordinates of Mobj

 INPUT: 
   xloc   = x location of point (in native Mobj coordinates)
   yloc   = y location of point (in native Mobj coordinates)
   Mobj   = Mesh object
           
 OUTPUT:
   Point = index of nearest vertex in the mesh
   Distance = Distance from x,y to Point in Mobj native coordinates

 EXAMPLE USAGE
    [Point,Distance] = find_nearest_point(50.1,100.2,Mobj)

 Author(s):  
    Geoff Cowles (University of Massachusetts Dartmouth)

 Revision history
   
==============================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Point,Distance] = find_nearest_pt(xloc,yloc,Mobj) 
0002 
0003 % Find nearest point in Mesh structure to (x,y)
0004 %
0005 % function [Point,Distance] = find_nearest_pt(xloc,yloc,Mobj)
0006 %
0007 % DESCRIPTION:
0008 %    Find nearest point to (xloc,yloc) in the domain of Mobj
0009 %    using native coordinates of Mobj
0010 %
0011 % INPUT:
0012 %   xloc   = x location of point (in native Mobj coordinates)
0013 %   yloc   = y location of point (in native Mobj coordinates)
0014 %   Mobj   = Mesh object
0015 %
0016 % OUTPUT:
0017 %   Point = index of nearest vertex in the mesh
0018 %   Distance = Distance from x,y to Point in Mobj native coordinates
0019 %
0020 % EXAMPLE USAGE
0021 %    [Point,Distance] = find_nearest_point(50.1,100.2,Mobj)
0022 %
0023 % Author(s):
0024 %    Geoff Cowles (University of Massachusetts Dartmouth)
0025 %
0026 % Revision history
0027 %
0028 %==============================================================================
0029 
0030 subname = 'find_nearest_pt';
0031 %fprintf('\n')
0032 %fprintf(['begin : ' subname '\n'])
0033 
0034 %------------------------------------------------------------------------------
0035 % Parse input arguments
0036 %------------------------------------------------------------------------------
0037 if(exist('xloc')*exist('yloc')*exist('Mobj') == 0)
0038     error('arguments to find_nearest_pt are missing')
0039 end;
0040 
0041 %------------------------------------------------------------------------------
0042 % Set native coordinates
0043 %------------------------------------------------------------------------------
0044 if(lower(Mobj.nativeCoords(1:3)) == 'car')
0045     x = Mobj.x;
0046     y = Mobj.y;
0047 else
0048     x = Mobj.lon;
0049     y = Mobj.lat;
0050 end;
0051 
0052 %------------------------------------------------------------------------------
0053 % Find the nearest point
0054 %------------------------------------------------------------------------------
0055 radvec = sqrt( (xloc-x).^2 + (yloc-y).^2);
0056 [Distance,Point] = min(radvec);
0057 
0058 
0059 %fprintf(['end   : ' subname '\n'])
0060 
0061

Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005