Generate a Hexagonal Array
Show older comments
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 Comments
davod naghavi
on 11 Feb 2021
i have this problem too. Did you solved it?
Image Analyst
on 11 Feb 2021
@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.
davod naghavi
on 12 May 2021
Thank you Dear @Image Analyst
Answers (2)
Image Analyst
on 25 Sep 2017
0 votes
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
on 7 Oct 2019
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 Comments
davod naghavi
on 12 May 2021
@Stijn Haenen Thank u . but i need as an n*n Array.
Image Analyst
on 13 May 2021
@davod naghavi, what do the rows and columns represent? Give an example of what you want.
Might want to start a new question.
davod naghavi
on 13 May 2021
@Image Analyst, I have a quite same problem. I actually want to make an nano-particle array with hexagonal symmetry. I need it in my project called fourier plane imahing microscopy. i need to analyse the fourier plane image. so during the pandemic i have only one option that is to simulate it. can you help??
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
on 11 Jun 2021
Edited: Image Analyst
on 11 Jun 2021
Nice. Depends on what form @Yrobel Lima wants though. There is also a new nsidedpoly() function that might be what someone wants.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!