Division of a square

1 view (last 30 days)
nand mourya
nand mourya on 16 May 2011
I have a square with vertices [0,0,1; 1,0,1; 1,1,1;0,1,1] I want to divide this square into 'n' number of equal squares. Lets say 16 equal squares. Could any one tell me the simplest way to do this?
thanks

Accepted Answer

Matt Fig
Matt Fig on 16 May 2011
I am not sure this is what you mean, but here is a graphical demonstration of what I think you mean.
% Data
n = 16; % Divide into n equal squares.
T = [0,0,1; 1,0,1; 1,1,1;0,1,1];
%
%
%
% Do the work:
m = 1/sqrt(n); % m should be an integer. Possibly add error check.
subplot(1,2,1)
patch(T(:,1),T(:,2),T(:,3),'b')
axis square
subplot(1,2,2)
hold on
SS = cell(1/m,1/m);
for ii = 1:1/m
for jj = 1:1/m
M = [T(:,1)*m+(ii-1)*m T(:,2)*m+(jj-1)*m T(:,3)];
patch(M(:,1),M(:,2),M(:,3),rand)
SS{ii,jj} = M; % Hold the arrays for further processing....
end
end
axis square
Note that if you don't need the graphics, you can just take that out of the loop.
  2 Comments
nand mourya
nand mourya on 16 May 2011
thanks matt! I was looking for the same.
nand mourya
nand mourya on 16 May 2011
In the above program, how do I get a list of all the vertices of the squares?
In simple words, I want a matrix ((4*n) X 3) which contains all the vertices.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!