Home > fvcom_prepro > inCell.m

inCell

PURPOSE ^

Find cell in mesh Mobj containing point (xpt,ypt)

SYNOPSIS ^

function [cell] = inCell(Mobj,xpt,ypt)

DESCRIPTION ^

 Find cell in mesh Mobj containing point (xpt,ypt)

 function [cell]  = inCell(Mobj,xpt,ypt)

 DESCRIPTION:
   Find cell in mesh Mobj containing point (xpt,ypt)

 INPUT
    Mobj = Matlab mesh object
    xpt = x position of point
    ypt = y position of point

 OUTPUT:
    cell = cell number (=0 if not found in mesh) 

 EXAMPLE USAGE
    cell = inCell(Mobj,5.,6.)

 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 [cell]  = inCell(Mobj,xpt,ypt)
0002 
0003 % Find cell in mesh Mobj containing point (xpt,ypt)
0004 %
0005 % function [cell]  = inCell(Mobj,xpt,ypt)
0006 %
0007 % DESCRIPTION:
0008 %   Find cell in mesh Mobj containing point (xpt,ypt)
0009 %
0010 % INPUT
0011 %    Mobj = Matlab mesh object
0012 %    xpt = x position of point
0013 %    ypt = y position of point
0014 %
0015 % OUTPUT:
0016 %    cell = cell number (=0 if not found in mesh)
0017 %
0018 % EXAMPLE USAGE
0019 %    cell = inCell(Mobj,5.,6.)
0020 %
0021 % Author(s):
0022 %    Geoff Cowles (University of Massachusetts Dartmouth)
0023 %
0024 % Revision history
0025 %
0026 %==============================================================================
0027 tri    = Mobj.tri;
0028 nElems = Mobj.nElems;
0029 x      = Mobj.x;
0030 y      = Mobj.y;
0031 cell   = 0;
0032 xc     = Mobj.xc;
0033 yc     = Mobj.yc;
0034 dist   = sqrt(  (xc-xpt).^2 + (yc-ypt).^2);
0035 
0036 cell = 0;
0037 %try nearest
0038 [rmin,imin] = min(dist); 
0039 if(isintriangle(x(tri(imin,1:3)),y(tri(imin,1:3)),xpt,ypt));  
0040   cell = imin; 
0041   return; 
0042 end;
0043 
0044 %sort from min distance to max and search along sort
0045 [distsort,ind] = sort(dist,1,'ascend');
0046 for i=1:nElems
0047    if(isintriangle(x(tri(ind(i),1:3)),y(tri(ind(i),1:3)),xpt,ypt));  
0048      cell = ind(i); 
0049      return
0050    end;
0051 end;
0052   
0053 % didn't find cell, just return nearest cell
0054 %cell = ind(1);

Generated on Wed 20-Feb-2019 16:06:01 by m2html © 2005