www.gusucode.com > Arduino_Engineering_Kit_Project_Files工具箱matlab程序 > Arduino_Engineering_Kit_Project_Files/DrawingRobot/HelperFunctions/reduceSegment.m

    function reducedSegment = reduceSegment(segment,radius)
% Copyright 2018 The MathWorks, Inc.

% Initialize variables needed 
nPoints = size(segment,1);
keepPoint = true(nPoints,1);
reference = 1;
test = 2;

% Select points to keep and remove such that each consecutive point
% remaining is separated by a minimum distance from the previous point
while test < nPoints
    % Check if test point is within given radius of reference point
    if norm(segment(test,:) - segment(reference,:)) < radius
        % If so, mark test point for removal and test the next point
        keepPoint(test) = false;
        test = test + 1;
    else
        % If not, update reference and test points
        reference = test;
        test = reference + 1;
    end
end

% Keep all points not marked for removal
reducedSegment = segment(keepPoint,:);