Home > matGeom > geom3d > intersectBoxes3d.m

intersectBoxes3d

PURPOSE ^

INTERSECTBOXES3D Intersection of two 3D bounding boxes.

SYNOPSIS ^

function box = intersectBoxes3d(box1, box2)

DESCRIPTION ^

INTERSECTBOXES3D Intersection of two 3D bounding boxes.

   RES = intersectBoxes3d(BOX1, BOX2)

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

   See also
   boxes3d, drawBox3d, mergeBoxes3d


 ------
 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 = intersectBoxes3d(box1, box2)
0002 %INTERSECTBOXES3D Intersection of two 3D bounding boxes.
0003 %
0004 %   RES = intersectBoxes3d(BOX1, BOX2)
0005 %
0006 %   Example
0007 %   box1 = [5 20 5 30 10 50];
0008 %   box2 = [0 15 0 15 0 20];
0009 %   intersectBoxes3d(box1, box2)
0010 %   ans =
0011 %       5 15 5 15 10 20
0012 %
0013 %   See also
0014 %   boxes3d, drawBox3d, mergeBoxes3d
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:2:end), box2(:,2:2:end));
0034 maxi = max(box1(:,1:2:end), box2(:,1:2:end));
0035 
0036 % concatenate result into a new box structure
0037 box = [maxi(:,1) mini(:,1) maxi(:,2) mini(:,2) maxi(:,3) mini(:,3)];
0038

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