Geometry library for matlab. Performs geometric computations on points, lines, circles, polygons...
function points = clipPoints(points, box)
%CLIPPOINTS Clip a set of points by a box
% CLIP = clipPoints(POINTS, BOX);
% Returns the set of points which are located inside of the box BOX.
% See also
% points2d, boxes2d, clipLine, drawPoint
% Author: David Legland
% e-mail: email@example.com
% Created: 2008-10-13, using Matlab 18.104.22.1687 (R2007a)
% Copyright 2010 INRA - Cepia Software Platform.
% get bounding box limits
xmin = box(1);
xmax = box(2);
ymin = box(3);
ymax = box(4);
% compute indices of points inside visible area
xOk = points(:,1)>=xmin & points(:,1)<=xmax;
yOk = points(:,2)>=ymin & points(:,2)<=ymax;
% keep only points inside box
points = points(xOk & yOk, :);