Generate a Hexagonal Array

15 次查看(过去 30 天)
Yrobel Lima
Yrobel Lima 2017-9-25
How can I make a hexagonal arrangement? I have a series of data that make up an array and I want to express it as a hexagonal map like figure.
Thanks a lot
  3 个评论
Image Analyst
Image Analyst 2021-2-11
@davod naghavi, we don't know. He never accepted any of the answers below. But since it's been over 3 years, I'd assume it was solved. And I doubt he'll answer you. Regardless, you can also look at the answers below and get your own solution.

请先登录,再进行评论。

回答(2 个)

Image Analyst
Image Analyst 2017-9-25
It's been talked about a lot before. Just search for it: https://www.mathworks.com/matlabcentral/answers/?term=tag%3A%22hexagon%22 and I'm sure you'll find code that you can adapt.

Stijn Haenen
Stijn Haenen 2019-10-7
base=1;
X=[];
Y=[];
for num=1:6
x=zeros(num*6,1);
y=zeros(num*6,1);
x(1:6)=base*num*cos(2*pi/6.*(0:5));
y(1:6)=base*num*sin(2*pi/6.*(0:5));
if num>1
for q=1:num-1
start_x=x(2)-q*base;
radi0=sqrt(start_x^2+y(2)^2);
start_alpha=1/3*pi+pi*1/3*1/(num)*q;
x(q*6+1:q*6+6)=radi0*cos(start_alpha+pi/3.*(1:6));
y(q*6+1:q*6+6)=radi0*sin(start_alpha+pi/3.*(1:6));
end
end
X=[X; x];
Y=[Y; y];
end
scatter(X,Y)
  6 个评论
Yro
Yro 2021-6-11
编辑:Yro 2021-6-11
Hi everyone,
The problem raised above I had done it with another account a few years ago. I found a solution using the scatteredInterpolant function in Matlab. Here I share a code in case it can help you.
Thanks in advance.
figure('rend','opengl','pos',[400 200 1024 720]);
% X -> vector (x coordinates)
% Y -> vector (y coordinates)
% Z -> vector (reactor power values)
% These arrays were taken from the simulation code
F = scatteredInterpolant(X,Y,Z,'nearest');
[X,Y] = ndgrid(linspace(min(X),max(X),1500),linspace(min(Y),max(Y),1500));
Z = F(X,Y);
POWER_map = surf(X, Y, Z, 'edgecolor', 'none');
R_FA = lattice_pitch/2;
Rx_Core = 11*R_FA; % Core radius
limitx = Rx_Core ;
ylim([-limitx limitx]);xlim([-limitx limitx]);
axis('square','off')
colormap('jet')
box off
grid on
view(a,90); % Vista en XY
% If you want to add values to each hexagon
xtext = COORDX(:,i);
ytext = COORDY(:,c);
ztext = POWER_FULL_CORE;
ztext(ceros) = NaN;
strmax = num2str(ztext,3);
t2 = text(xtext,ytext,ztext,strmax,'HorizontalAlignment','center','VerticalAlignment','middle', 'FontSize', 10);
Image Analyst
Image Analyst 2021-6-11
编辑:Image Analyst 2021-6-11
Nice. Depends on what form @Yrobel Lima wants though. There is also a new nsidedpoly() function that might be what someone wants.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by