SQUAREGRID Generate equally spaces points in plane. usage PTS = squareGrid(BOUNDS, ORIGIN, SIZE) generate points, lying in the window defined by BOUNDS (=[xmin ymin xmax ymax]), starting from origin with a constant step equal to size. Example PTS = squareGrid([0 0 10 10], [3 3], [4 2]) will return points : [3 1;7 1;3 3;7 3;3 5;7 5;3 7;7 7;3 9;7 9]; TODO: add possibility to use rotated grid --------- author : David Legland INRA - TPV URPOI - BIA IMASTE created the 06/08/2005.
0001 function varargout = squareGrid(bounds, origin, size) 0002 %SQUAREGRID Generate equally spaces points in plane. 0003 % 0004 % usage 0005 % PTS = squareGrid(BOUNDS, ORIGIN, SIZE) 0006 % generate points, lying in the window defined by BOUNDS (=[xmin ymin 0007 % xmax ymax]), starting from origin with a constant step equal to size. 0008 % 0009 % Example 0010 % PTS = squareGrid([0 0 10 10], [3 3], [4 2]) 0011 % will return points : 0012 % [3 1;7 1;3 3;7 3;3 5;7 5;3 7;7 7;3 9;7 9]; 0013 % 0014 % 0015 % 0016 % TODO: add possibility to use rotated grid 0017 % 0018 % --------- 0019 % 0020 % author : David Legland 0021 % INRA - TPV URPOI - BIA IMASTE 0022 % created the 06/08/2005. 0023 % 0024 0025 % find all x coordinate 0026 x1 = bounds(1) + mod(origin(1)-bounds(1), size(1)); 0027 x2 = bounds(3) - mod(bounds(3)-origin(1), size(1)); 0028 lx = (x1:size(1):x2)'; 0029 0030 % find all y coordinate 0031 y1 = bounds(2) + mod(origin(2)-bounds(2), size(2)); 0032 y2 = bounds(4) - mod(bounds(4)-origin(2), size(2)); 0033 ly = (y1:size(2):y2)'; 0034 0035 % number of points in each coord, and total number of points 0036 ny = length(ly); 0037 nx = length(lx); 0038 np = nx*ny; 0039 0040 % create points 0041 pts = zeros(np, 2); 0042 for i=1:ny 0043 pts( (1:nx)'+(i-1)*nx, 1) = lx; 0044 pts( (1:nx)'+(i-1)*nx, 2) = ly(i); 0045 end 0046 0047 % process output 0048 if nargout>0 0049 varargout{1} = pts; 0050 end