Random Wisdom

Tesselated Cells

by on Feb.03, 2006, under How To ..., Software

Finally .. a script (link broken since 2007) 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.

:, ,

2 Comments for this entry

  • Buzby

    Hey Mostafa,

    Nice blog! The link to your Tesselated Cells script (tess_cells.m) doesn’t seem to be working, do you think you could fix it as I’d really like to see how you do the square tesselation. Many thanks.

  • Mostafa

    Hi Buzby,

    unfortunately I lost that particular *.m file when the server hosting it went down. If I can remember what I did, I’ll follow up with another comment.

    -M

Leave a Reply