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 件)

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by