This blog has moved! Redirecting...
You should be automatically redirected. If not, visit http://scrolls.mafgani.net/ and update your bookmarks.

Friday, February 03, 2006

Tesselated Cells

Finally .. a script that will generate a square field of tesselated cells in MATLAB. The script take as input the desired cell radius and the dimension of the square field.

Generating a cell is simple enough. The corners are simply R*exp(j*(-pi:pi/3:pi)+pi/6)/cos(pi/6). The additional pi/6 is needed to rotate the resulting hexagon. The real challenge is in the tesselation. In order to achieve that, two base vectors that govern the tesselation must be defined:


vi = 2*R;
vj = 2*R*(cos(pi/3) + j*sin(pi/3))


Using these base vectors, the centers of every cell in the tesselation can be defined:


for a = 1:x
for b = 1:x
centr(a,b) = a*vi+b*vj;
end
end


One we have the centers, use the MATLAB repmat function to replicate the corners around each of the centers to get the tesselated cells:


cells = repmat(corners.', 1,...
numel(centr))+repmat(reshape(centr.',1,...
numel(centr)),length(corners), 1);


A plot of the cells can be achieved using:


plot(real(cells),imag(cells));


This will however, generate a tesselation that is skewed. The linked *.m file takes care of that issue to generate a square tesselated field.

0 Comments:

Post a Comment

<< Home