📄 hex_centers.m
字号:
function [vCx, vCy] = hex_centers(a, tri_size1, tri_size2, type)
% [xCenters, yCenters] = HEX_CENTERS(a, firstRing, lastRing, type)
% Calculates the coordinates of points on a hexagonal lattice
% a is the lattice pitch.
% firstRing is the number of points per hexagon side in the
% first ring. lastRing is the number of points per hexagon side in
% the last ring.
% type is either 1 or 2, which determines which one of the two
% types of lattices is calculated.
tri_size1 = tri_size1+1;
tri_size2 = tri_size2+1;
vCx = [];
vCy = [];
for row = tri_size1:tri_size2
for col = 1:(row-1)
for tri = 1:6
% calculate vein centers
x0 = -a/2*(row-1)+a*(col-1);
y0 = a*sqrt(3)/2*(row-1);
xc = cos(pi/3*(tri-1))*x0 + sin(pi/3*(tri-1))*y0;
yc = -sin(pi/3*(tri-1))*x0 + cos(pi/3*(tri-1))*y0;
R = xc + j*yc;
if type == 2
xc = real(abs(R)*exp(j*(angle(R)+pi/6)));
yc = imag(abs(R)*exp(j*(angle(R)+pi/6)));
end
vCx = [vCx xc];
vCy = [vCy yc];
end
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -