HexagonLatticePosition(ring,separation,center,key)
%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 (2024). HexagonLatticePosition(ring,separation,center,key) (https://www.mathworks.com/matlabcentral/fileexchange/52280-hexagonlatticeposition-ring-separation-center-key), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |