【matlab】画正六边形、矩形、圆形点阵

矩形

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 <=2
        if n == 1
            rho(1,1)=0;
            theta(1,1)=0;
        end
        if n == 2
            for i = 1:6
                rho(1,1+i)=4.5;
                 theta(1,1+i)=2*pi/6*(i)+30/180*pi;
            end
        end
    else
        for j = 1:(n-1)*6
            rho(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+1
        x(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');

在这里插入图片描述

  • 8
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值