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