Home > matGeom > geom3d > randomPointInBox3d.m

randomPointInBox3d

PURPOSE ^

RANDOMPOINTINBOX3D Generate random point(s) within a 3D box.

SYNOPSIS ^

function points = randomPointInBox3d(box, N, varargin)

DESCRIPTION ^

RANDOMPOINTINBOX3D Generate random point(s) within a 3D box.

   PTS = randomPointInBox3d(BOX)
   Generate a random point within the 3D box BOX. The result is a 1-by-3
   row vector.

   PTS = randomPointInBox3d(BOX, N)
   Generates N points within the box. The result is a N-by-3 array.

   BOX has the format:
   BOX = [XMIN XMAX YMIN YMAX ZMIN ZMAX].

   Example
     % draw points within a box
     box = [10 40 20 60 30 50];
     pts =  randomPointInBox3d(box, 500);
     figure(1); hold on;
     drawBox3d(box);
     drawPoint3d(pts, '.');
     axis('equal');
     axis([0 100 0 100 0 100]);
     view(3);

   See also
   points3d, boxes3d

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function points = randomPointInBox3d(box, N, varargin)
0002 %RANDOMPOINTINBOX3D Generate random point(s) within a 3D box.
0003 %
0004 %   PTS = randomPointInBox3d(BOX)
0005 %   Generate a random point within the 3D box BOX. The result is a 1-by-3
0006 %   row vector.
0007 %
0008 %   PTS = randomPointInBox3d(BOX, N)
0009 %   Generates N points within the box. The result is a N-by-3 array.
0010 %
0011 %   BOX has the format:
0012 %   BOX = [XMIN XMAX YMIN YMAX ZMIN ZMAX].
0013 %
0014 %   Example
0015 %     % draw points within a box
0016 %     box = [10 40 20 60 30 50];
0017 %     pts =  randomPointInBox3d(box, 500);
0018 %     figure(1); hold on;
0019 %     drawBox3d(box);
0020 %     drawPoint3d(pts, '.');
0021 %     axis('equal');
0022 %     axis([0 100 0 100 0 100]);
0023 %     view(3);
0024 %
0025 %   See also
0026 %   points3d, boxes3d
0027 %
0028 % ------
0029 % Author: David Legland
0030 % e-mail: david.legland@grignon.inra.fr
0031 % Created: 2011-06-27,    using Matlab 7.9.0.529 (R2009b)
0032 % Copyright 2011 INRA - Cepia Software Platform.
0033 
0034 if nargin < 2
0035     N = 1;
0036 end
0037 
0038 % extract box bounds
0039 xmin = box(1);
0040 ymin = box(3);
0041 zmin = box(5);
0042 
0043 % compute size of box
0044 dx = box(2) - xmin;
0045 dy = box(4) - ymin;
0046 dz = box(6) - zmin;
0047 
0048 % compute point coordinates
0049 points = [rand(N, 1)*dx+xmin , rand(N, 1)*dy+ymin , rand(N, 1)*dz+zmin];
0050

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