Home > matGeom > geom2d > boundingBox.m

boundingBox

PURPOSE ^

BOUNDINGBOX Bounding box of a set of points.

SYNOPSIS ^

function box = boundingBox(points)

DESCRIPTION ^

BOUNDINGBOX Bounding box of a set of points.

   BOX = boundingBox(POINTS)
   Returns the bounding box of the set of points POINTS. POINTS can be
   either a N-by-2 or N-by-3 array. The result BOX is a 1-by-4 or 1-by-6
   array, containing:
   [XMIN XMAX YMIN YMAX] (2D point sets)
   [XMIN XMAX YMIN YMAX ZMIN ZMAX] (3D point sets)

   Example
   % Draw the bounding box of a set of random points
     points = rand(30, 2);
     figure; hold on;
     drawPoint(points, '.');
     box = boundingBox(points);
     drawBox(box, 'r');

   % Draw bounding box of a cubeoctehedron
     [v e f] = createCubeOctahedron;
     box3d = boundingBox(v);
     figure; hold on;
     drawMesh(v, f);
     drawBox3d(box3d);
     set(gcf, 'renderer', 'opengl')
     axis([-2 2 -2 2 -2 2]);
     view(3)
     
   See also
   polygonBounds, drawBox

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function box = boundingBox(points)
0002 %BOUNDINGBOX Bounding box of a set of points.
0003 %
0004 %   BOX = boundingBox(POINTS)
0005 %   Returns the bounding box of the set of points POINTS. POINTS can be
0006 %   either a N-by-2 or N-by-3 array. The result BOX is a 1-by-4 or 1-by-6
0007 %   array, containing:
0008 %   [XMIN XMAX YMIN YMAX] (2D point sets)
0009 %   [XMIN XMAX YMIN YMAX ZMIN ZMAX] (3D point sets)
0010 %
0011 %   Example
0012 %   % Draw the bounding box of a set of random points
0013 %     points = rand(30, 2);
0014 %     figure; hold on;
0015 %     drawPoint(points, '.');
0016 %     box = boundingBox(points);
0017 %     drawBox(box, 'r');
0018 %
0019 %   % Draw bounding box of a cubeoctehedron
0020 %     [v e f] = createCubeOctahedron;
0021 %     box3d = boundingBox(v);
0022 %     figure; hold on;
0023 %     drawMesh(v, f);
0024 %     drawBox3d(box3d);
0025 %     set(gcf, 'renderer', 'opengl')
0026 %     axis([-2 2 -2 2 -2 2]);
0027 %     view(3)
0028 %
0029 %   See also
0030 %   polygonBounds, drawBox
0031 %
0032 
0033 % ------
0034 % Author: David Legland
0035 % e-mail: david.legland@inra.fr
0036 % Created: 2011-04-01,    using Matlab 7.9.0.529 (R2009b)
0037 % Copyright 2011 INRA - Cepia Software Platform.
0038 
0039 % HISTORY
0040 % 2011-04-08 add example
0041 % 2011-12-09 rename to boundingBox
0042 
0043 % compute extreme x and y values
0044 xmin = min(points(:,1));
0045 xmax = max(points(:,1));
0046 ymin = min(points(:,2));
0047 ymax = max(points(:,2));
0048 
0049 if size(points, 2) > 2
0050     % process case of 3D points
0051     zmin = min(points(:,3));
0052     zmax = max(points(:,3));
0053     
0054     % format as box 3D data structure
0055     box = [xmin xmax ymin ymax zmin zmax];
0056 else
0057     % format as box data structure
0058     box = [xmin xmax ymin ymax];
0059 end

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