作者:zfy,转载请注明
画多层六边形,蜂窝状,第一个和第二个参数为最中心小区的横纵坐标,第三个参数为小区半径,第四个为所需画的层数(如果只画第一个六边形拿出程序中底下部分cirliu即可,只一个六边形视为第0层,该参数>=1)。我们通常需要它在一个矩形界面中显示,那么将蜂窝中心放在矩形中心,然后试着运行一个程序,看在半径为r的情况下几层能布满即可。
%%%%%%%%%%%%%%%%%%%%%by
zfy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function qunliu( xx,yy,r,ceng )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hang=linspace(0,2*pi,7);
for
i=1:1:ceng
for j=1:1:length(hang) theta(i,i*j-i+1) = hang(j);
cx(i,i*j-i+1)=sqrt(3)*i*r*cos(theta(i,i*j-i+1)); %这是每层上角度为pi/3,2*pi/3...小区中心
cy(i,i*j-i+1)=sqrt(3)*i*r*sin(theta(i,i*j-i+1));
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(ceng>=2)
for i=2:1:ceng
for
j=1:1:length(hang)-1 for
k=1:1:i-1 %求那些非pi/3整数倍角