Home > mrg > MRG_utilities > mrg_in_radius.m

mrg_in_radius

PURPOSE ^

Are points within a specified radius of a target point?

SYNOPSIS ^

function radius_index = mrg_in_radius(targetx, targety, x, y, radius)

DESCRIPTION ^

 Are points within a specified radius of a target point?

 INPUT
   targetx     Target X value
   targety     Target Y value
   x           Vector of x values to test
   y           Vector of y values to test (must be same length as x)
   radius      The radius of the circle around [targetx, targety]

 OUTPUT
   radius_index    An index the same length as x and y, specifying the
                   points within the specified radius.  
 
 LICENCE
   Created by Daniel Pritchard (www.pritchard.co)
   Distributed under a creative commons CC BY-SA licence. See here:
   http://creativecommons.org/licenses/by-sa/3.0/

 DEVELOPMENT
   v 1.0   2012
           DP.  Initial development
   v 1.1   14/02/2013
           DP.  Documentation.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function radius_index = mrg_in_radius(targetx, targety, x, y, radius)
0002 % Are points within a specified radius of a target point?
0003 %
0004 % INPUT
0005 %   targetx     Target X value
0006 %   targety     Target Y value
0007 %   x           Vector of x values to test
0008 %   y           Vector of y values to test (must be same length as x)
0009 %   radius      The radius of the circle around [targetx, targety]
0010 %
0011 % OUTPUT
0012 %   radius_index    An index the same length as x and y, specifying the
0013 %                   points within the specified radius.
0014 %
0015 % LICENCE
0016 %   Created by Daniel Pritchard (www.pritchard.co)
0017 %   Distributed under a creative commons CC BY-SA licence. See here:
0018 %   http://creativecommons.org/licenses/by-sa/3.0/
0019 %
0020 % DEVELOPMENT
0021 %   v 1.0   2012
0022 %           DP.  Initial development
0023 %   v 1.1   14/02/2013
0024 %           DP.  Documentation.
0025 
0026 %% Go!
0027 if length(x)~=length(y)
0028     error('x and y must be equal length')
0029 end
0030 zeroed_x = x-targetx;
0031 zeroed_y = y-targety;
0032 % Not worried about east vs north here becuase all we need is magnitude...
0033 [~, mag] = cart2pol(zeroed_x, zeroed_y);
0034 radius_index = mag<radius;
0035 end

Generated on Thu 29-May-2014 21:29:53 by m2html © 2005