Home > matGeom > geom2d > mergeBoxes.m

mergeBoxes

PURPOSE ^

MERGEBOXES Merge two boxes, by computing their greatest extent.

SYNOPSIS ^

function box = mergeBoxes(box1, box2)

DESCRIPTION ^

MERGEBOXES Merge two boxes, by computing their greatest extent.

   BOX = mergeBoxes(BOX1, BOX2);

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


   See also
   boxes2d, drawBox, intersectBoxes

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022