Home > utilities > surrounders.m

surrounders

PURPOSE ^

Return the IDs of the nodes surrounding node number `n'.

SYNOPSIS ^

function nodes = surrounders(n, triangles)

DESCRIPTION ^

 Return the IDs of the nodes surrounding node number `n'.

 INPUTS:
   n
       Node ID around which to find the connected nodes.
   triangles
       Triangulation matrix to find the connected nodes.

 OUTPUTS:
   surroundingidx
       Indices of the surrounding nodes.

 Author(s):
   Pierre Cazenave (Plymouth Marine Laboratory)

 Revision history:
   2015-02-19 First version based on the PyFVCOM.grid_tools surrounders
   function.

 Notes:

 Check it works with:
 [x, y] = meshgrid(1:25, 100:125);
 x = x(:) + randn(numel(x), 1) * 0.1;
 y = y(:) + randn(numel(y), 1) * 0.1;
 tri = delaunay([x, y]);
 for n = linspace(1, length(x) - 1, 5)
       aa = surrounders(n, tri)
       figure
       triplot(x, y, tri)
       plot(x(n), y(n), 'ro')
       plot(x(aa), y(aa), 'ko')
       xlim(min(x(aa)) - 1, max(x(aa)) + 1)
       ylim(min(y(aa)) - 1, max(y(aa)) + 1)
       legend
 end

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function nodes = surrounders(n, triangles)
0002 % Return the IDs of the nodes surrounding node number `n'.
0003 %
0004 % INPUTS:
0005 %   n
0006 %       Node ID around which to find the connected nodes.
0007 %   triangles
0008 %       Triangulation matrix to find the connected nodes.
0009 %
0010 % OUTPUTS:
0011 %   surroundingidx
0012 %       Indices of the surrounding nodes.
0013 %
0014 % Author(s):
0015 %   Pierre Cazenave (Plymouth Marine Laboratory)
0016 %
0017 % Revision history:
0018 %   2015-02-19 First version based on the PyFVCOM.grid_tools surrounders
0019 %   function.
0020 %
0021 % Notes:
0022 %
0023 % Check it works with:
0024 % [x, y] = meshgrid(1:25, 100:125);
0025 % x = x(:) + randn(numel(x), 1) * 0.1;
0026 % y = y(:) + randn(numel(y), 1) * 0.1;
0027 % tri = delaunay([x, y]);
0028 % for n = linspace(1, length(x) - 1, 5)
0029 %       aa = surrounders(n, tri)
0030 %       figure
0031 %       triplot(x, y, tri)
0032 %       plot(x(n), y(n), 'ro')
0033 %       plot(x(aa), y(aa), 'ko')
0034 %       xlim(min(x(aa)) - 1, max(x(aa)) + 1)
0035 %       ylim(min(y(aa)) - 1, max(y(aa)) + 1)
0036 %       legend
0037 % end
0038 
0039 eidx = max((abs(triangles - n) == 0), [], 2);
0040 nodes = unique(triangles(triangles(eidx) ~= n, :));

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