hex_centers.m
来自「利用电磁场的源激发方法来计算光子晶体波导例如光子晶体光纤」· M 代码 · 共 32 行
M
32 行
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 + =
减小字号Ctrl + -
显示快捷键?