Generate a Hexagonal Array
조회 수: 23 (최근 30일)
이전 댓글 표시
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
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
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.
댓글 수: 0
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
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
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 Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!