Home > matGeom > geom2d > mergeClosePoints.m

mergeClosePoints

PURPOSE ^

MERGECLOSEPOINTS Merge points that are closer than a given distance.

SYNOPSIS ^

function points = mergeClosePoints(points, varargin)

DESCRIPTION ^

MERGECLOSEPOINTS Merge points that are closer than a given distance.

   PTS2 = mergeClosePoints(PTS, DIST)
   Remove points in the array PTS such that no points closer than the
   distance DIST remain in the array.

   PTS2 = mergeClosePoints(PTS)
   If the distance is not specified, the default value 1e-14 is used.


   Example
     pts = rand(200, 2);
     pts2 = mergeClosePoints(pts, .1);
     figure; drawPoint(pts, '.');
     hold on; drawPoint(pts2, 'mo');

   See also
     points2d, removeMultipleVertices

 ------
 Author: David Legland
 e-mail: david.legland@grignon.inra.fr
 Created: 2013-10-04,    using Matlab 7.9.0.529 (R2009b)
 Copyright 2013 INRA - Cepia Software Platform.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function points = mergeClosePoints(points, varargin)
0002 %MERGECLOSEPOINTS Merge points that are closer than a given distance.
0003 %
0004 %   PTS2 = mergeClosePoints(PTS, DIST)
0005 %   Remove points in the array PTS such that no points closer than the
0006 %   distance DIST remain in the array.
0007 %
0008 %   PTS2 = mergeClosePoints(PTS)
0009 %   If the distance is not specified, the default value 1e-14 is used.
0010 %
0011 %
0012 %   Example
0013 %     pts = rand(200, 2);
0014 %     pts2 = mergeClosePoints(pts, .1);
0015 %     figure; drawPoint(pts, '.');
0016 %     hold on; drawPoint(pts2, 'mo');
0017 %
0018 %   See also
0019 %     points2d, removeMultipleVertices
0020 %
0021 % ------
0022 % Author: David Legland
0023 % e-mail: david.legland@grignon.inra.fr
0024 % Created: 2013-10-04,    using Matlab 7.9.0.529 (R2009b)
0025 % Copyright 2013 INRA - Cepia Software Platform.
0026 
0027 % default values
0028 minDist = 1e-14;
0029 if ~isempty(varargin)
0030     minDist = varargin{1};
0031 end
0032 
0033 i = 1;
0034 while i < size(points, 1)
0035     dist = distancePoints(points(i,:), points);
0036     inds = dist < minDist;
0037     inds(i) = 0;
0038     
0039     points(inds, :) = [];
0040     
0041     % switch to next point
0042     i = i + 1;
0043 end

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019