Hexagonal grid representing a cellular network as used in mobile communication systems

大兔子大兔子 提交于 2019-12-06 11:12:19

A few years ago I wrote some code to do just that:

%// Define input data:
close all
clear all
M_max = 14; %// number of cells in vertical direction
N_max = 10; %// number of cells in horizontal direction
trans = 1;  %// hexagon orientation (0 or 1)

%// Do the plotting:
hold on
for m = -M_max:M_max
    for n = -N_max:N_max
        center = [.5 sqrt(3)/2] + m*[0 -sqrt(3)] + n*[3/2 sqrt(3)/2];
        if ~trans
            plot([center(1)-1 center(1)],[center(2) center(2)])
            plot([center(1) center(1)+1/2],[center(2) center(2)+sqrt(3)/2])
            plot([center(1) center(1)+1/2],[center(2) center(2)-sqrt(3)/2])
        else %// exchange the two arguments to `plot`
            plot([center(2) center(2)],[center(1)-1 center(1)])
            plot([center(2) center(2)+sqrt(3)/2],[center(1) center(1)+1/2])
            plot([center(2) center(2)-sqrt(3)/2],[center(1) center(1)+1/2])
        end %if
    end %for
end %for
plot([-15 15],[0 0],'-.') %// adjust length manually
plot([-15 15],[-15*sqrt(3) 15*sqrt(3)],'-.') %// adjust length manually
axis image
set(gca,'xtick',[])
set(gca,'ytick',[])
axis([-10 10 -13.3 13.3]) %// adjust axis size manually
set(gca,'Visible','off') %// handy for printing the image

For example, this is the image generated with the above data:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!