function xyz=hexgrid(lside, nx, ny) Return the relative coordinates of a hex 'grid' centered at 0,0, of half-width nx x ny (see gethex()) Inputs: lside - The length of a hex side, in radians nx - The half-width of the hex grid. An integral number of pointings, spaced along a great circle ny - The half-width of the hex grid. An integral number of pointings, spaced along the perpendicular great circle Outputs: xyz - The XYZ coordinates of the hex vertices (EML)
0001 function xyz=hexgrid(lside, nx, ny) 0002 0003 % function xyz=hexgrid(lside, nx, ny) 0004 % 0005 % Return the relative coordinates of a hex 'grid' centered at 0,0, of 0006 % half-width nx x ny (see gethex()) 0007 % 0008 % Inputs: 0009 % 0010 % lside - The length of a hex side, in radians 0011 % 0012 % nx - The half-width of the hex grid. An integral number of 0013 % pointings, spaced along a great circle 0014 % 0015 % ny - The half-width of the hex grid. An integral number of 0016 % pointings, spaced along the perpendicular great circle 0017 % 0018 % Outputs: 0019 % 0020 % xyz - The XYZ coordinates of the hex vertices 0021 % 0022 % (EML) 0023 0024 ixmin = -2*nx; 0025 ixmax = 2*nx; 0026 iymin = -ny; 0027 iymax = ny; 0028 0029 hside = lside * cos(pi/6); 0030 0031 iv=1; 0032 for iy=iymin:iymax 0033 0034 if(mod(iy, 2)==0) 0035 ixmintmp = ixmin; 0036 else 0037 ixmintmp = ixmin+1; 0038 end 0039 0040 for ix=ixmintmp:2:ixmax 0041 0042 % I flipped these around to have the shorter spacing along lines of 0043 % constant dec 0044 0045 dy = lside/2 * ix; 0046 dx = hside * iy; 0047 0048 xv(iv) = dx; 0049 yv(iv) = dy; 0050 0051 theta(iv) = atan2(dy, dx); 0052 0053 darc(iv) = sqrt(dx*dx + dy*dy); 0054 0055 r(iv) = sin(darc(iv)); 0056 0057 xt(iv) = r(iv) * cos(theta(iv)); 0058 yt(iv) = r(iv) * sin(theta(iv)); 0059 zt(iv) = cos(darc(iv)); 0060 0061 iv = iv+1; 0062 end 0063 0064 end 0065 0066 xyz = [xt; yt; zt]; 0067 0068 return