SIMPLIFYPOLYGON Douglas-Peucker simplification of a polygon. POLY2 = simplifyPolygon(POLY, TOL) Simplifies the input polygon using the Douglas-Peucker algorithm. Example elli = [20 30 40 20 30]; poly = ellipseToPolygon(elli, 500); poly2 = simplifyPolygon(poly, 1); % use a tolerance equal to 1. figure; hold on; drawEllipse(elli); drawPoint(poly2, 'mo'); See also polygons2d, smoothPolygon, simplifyPolyline, resamplePolygon References http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
0001 function [poly, keepInds] = simplifyPolygon(poly, varargin) 0002 %SIMPLIFYPOLYGON Douglas-Peucker simplification of a polygon. 0003 % 0004 % POLY2 = simplifyPolygon(POLY, TOL) 0005 % Simplifies the input polygon using the Douglas-Peucker algorithm. 0006 % 0007 % Example 0008 % elli = [20 30 40 20 30]; 0009 % poly = ellipseToPolygon(elli, 500); 0010 % poly2 = simplifyPolygon(poly, 1); % use a tolerance equal to 1. 0011 % figure; hold on; 0012 % drawEllipse(elli); 0013 % drawPoint(poly2, 'mo'); 0014 % 0015 % See also 0016 % polygons2d, smoothPolygon, simplifyPolyline, resamplePolygon 0017 % 0018 % References 0019 % http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm 0020 % 0021 0022 % ------ 0023 % Author: David Legland 0024 % e-mail: david.legland@inra.fr 0025 % Created: 2013-03-14, using Matlab 7.9.0.529 (R2009b) 0026 % Copyright 2013 INRA - Cepia Software Platform. 0027 0028 % call the simplifyPolyline function by ensuring the last vertex is present 0029 poly = poly([1:end 1], :); 0030 [poly, keepInds] = simplifyPolyline(poly, varargin{:}); 0031 0032 % remove last vertex 0033 poly(end, :) = []; 0034 keepInds(end) = [];