Home > matGeom > geom2d > intersectBoxes.m

intersectBoxes

PURPOSE ^

INTERSECTBOXES Intersection of two bounding boxes.

SYNOPSIS ^

function box = intersectBoxes(box1, box2)

DESCRIPTION ^

INTERSECTBOXES Intersection of two bounding boxes.

   RES = intersectBoxes(BOX1, BOX2)

   Example
   box1 = [5 20 5 30];
   box2 = [0 15 0 15];
   intersectBoxes(box1, box2)
   ans = 
       5 15 5 15

   See also
   boxes2d, drawBox, mergeBoxes


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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function box = intersectBoxes(box1, box2)
0002 %INTERSECTBOXES Intersection of two bounding boxes.
0003 %
0004 %   RES = intersectBoxes(BOX1, BOX2)
0005 %
0006 %   Example
0007 %   box1 = [5 20 5 30];
0008 %   box2 = [0 15 0 15];
0009 %   intersectBoxes(box1, box2)
0010 %   ans =
0011 %       5 15 5 15
0012 %
0013 %   See also
0014 %   boxes2d, drawBox, mergeBoxes
0015 %
0016 %
0017 % ------
0018 % Author: David Legland
0019 % e-mail: david.legland@grignon.inra.fr
0020 % Created: 2010-07-26,    using Matlab 7.9.0.529 (R2009b)
0021 % Copyright 2010 INRA - Cepia Software Platform.
0022 
0023 % unify sizes of data
0024 if size(box1,1) == 1
0025     box1 = repmat(box1, size(box2,1), 1);
0026 elseif size(box2, 1) == 1
0027     box2 = repmat(box2, size(box1,1), 1);
0028 elseif size(box1,1) ~= size(box2,1)
0029     error('Bad size for inputs');
0030 end
0031 
0032 % compute extreme coords
0033 mini = min(box1(:,[2 4]), box2(:,[2 4]));
0034 maxi = max(box1(:,[1 3]), box2(:,[1 3]));
0035 
0036 % concatenate result into a new box structure
0037 box = [maxi(:,1) mini(:,1) maxi(:,2) mini(:,2)];

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