Division of a square

1 次查看(过去 30 天)
nand mourya
nand mourya 2011-5-16
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

采纳的回答

Matt Fig
Matt Fig 2011-5-16
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 个评论
nand mourya
nand mourya 2011-5-16
thanks matt! I was looking for the same.
nand mourya
nand mourya 2011-5-16
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.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by