You are now following this Submission
- You will see updates in your followed content feed
- You may receive emails, depending on your communication preferences
%HexagonLatticePosition(ring,separation,center,key) generates the x and y
%coordinates for a number rings of hexagon.
% Inputs:
% ring: the number of rings. Note, the center point is regarded as the
% first ring. Thus the number for ring has to equal or larger than 1.
% separation: the separation between each two adjacent points;
% center: the center coordinates for the hexgonal window
% key: to include the center point or not. 1: yes, 0: no.
% Detailed explanation goes here
h=sqrt(3)/2*separation; % the height for the unit triangle
row=2*ring-1; % how many rows of data
xdata=cell(1,row);
ydata=cell(1,row);
for ii=1:ring
vector_size=ring+ii-1;
if ii<ring
xx=[0:vector_size-1]*separation-(vector_size-1)*separation/2-center(1);
yy=(ring-ii)*h*ones(1,vector_size)-center(2);
xdata{ii}=xx;
xdata{row+1-ii}=xx;
ydata{ii}=yy;
ydata{row+1-ii}=-1*yy;
else
xx=[0:vector_size-1]*separation-(vector_size-1)*separation/2-center(1);
yy=(ring-ii)*h*ones(1,vector_size)-center(2);
xdata{ii}=xx;
ydata{ii}=yy;
end
end
xxx=[];
yyy=[];
for ii=1:row;
xxx=[xxx,xdata{ii}];
yyy=[yyy,ydata{ii}];
end
if key ==0
middle=(length(xxx)+1)/2;
x1=xxx(1:middle-1);
y1=yyy(1:middle-1);
x2=xxx(middle+1:end);
y2=yyy(middle+1:end);
xxx=[x1,x2];
yyy=[y1,y2];
end
Cite As
Long Wang (2026). HexagonLatticePosition(ring,separation,center,key) (https://se.mathworks.com/matlabcentral/fileexchange/52280-hexagonlatticeposition-ring-separation-center-key), MATLAB Central File Exchange. Retrieved .
General Information
- Version 1.0.0.0 (1.46 KB)
MATLAB Release Compatibility
- Compatible with any release
Platform Compatibility
- Windows
- macOS
- Linux
| Version | Published | Release Notes | Action |
|---|---|---|---|
| 1.0.0.0 |
