clc;clear;%%正方形排列
n=22;%为奇数,表示几x几的矩阵
a=zeros(n,n,2);%初始化
for i=1:n
for j=1:n
a(i,j,1)=-4.5*((n-1)/2)+4.5*(j-1);a(i,j,2)=4.5*((n-1)/2)-4.5*(i-1);
end
end
x=reshape(a(:,:,1),1,n*n);
y=reshape(a(:,:,2),1,n*n);plot(x,y,'o');[X,Y]=cart2pol(x*1e-3,y*1e-3);
圆形
clc;clear;%%圆形排列
N=16;%圆形的个数
rho=zeros(1,3*N*(N-1)+1);
theta=zeros(1,3*N*(N-1)+1);rho(1,1)=0;theta(1,1)=0;for n=1:N
if n <=2if n ==1rho(1,1)=0;theta(1,1)=0;
end
if n ==2for i =1:6rho(1,1+i)=4.5;theta(1,1+i)=2*pi/6*(i)+30/180*pi;
end
end
elsefor j =1:(n-1)*6rho(1,3*(n-1)*(n-2)+1+j)=4.5*(n-1);theta(1,3*(n-1)*(n-2)+1+j)=2*pi/(n-1)/6*(j-1)+30/180*pi;
end
end
end
polar(theta,rho,'o');
rho=rho*1e-3;
正六边形
clc;
clear;%% 给定六边形的边长数量n,且n为正整数
n=10;
x=zeros(n,n+1);
y=zeros(n,n+1);%% 定义各个点的坐标
for i=1:n
for j=1:i+1x(i,j)=2*i-(j-1);y(i,j)=(j-1)*sqrt(3);
end
end
xx=reshape(x,1,(n+1)*n);
yy=reshape(y,1,(n+1)*n);plot(xx,yy,'x')[theta,rou]=cart2pol(xx,yy);
theta1=theta+1*2*pi/6;
theta2=theta+2*2*pi/6;
theta3=theta+3*2*pi/6;
theta4=theta+4*2*pi/6;
theta5=theta+5*2*pi/6;
theta=[theta,theta1,theta2,theta3,theta4,theta5];
rou=[rou,rou,rou,rou,rou,rou];[xxx,yyy]=pol2cart(theta,rou);plot(xxx,yyy,'x');