我是靠谱客的博主 失眠皮卡丘,这篇文章主要介绍【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');

在这里插入图片描述

最后

以上就是失眠皮卡丘最近收集整理的关于【matlab】画正六边形、矩形、圆形点阵的全部内容,更多相关【matlab】画正六边形、矩形、圆形点阵内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部