{  
determines spacing of evenly spaced dot pattern (diamond grid) of specified 
coverage given v/u ratio (oblongness of diamond) and radius of dot

A1:coverage
A2:v/u
A3:radius

example:

#A1 coverage A2 V/U spacing A3 radius
void mixfunc EG2
4 frit glz refl dots.cal
0
3 .5 r  .0104

extend to variable spacing by replacing A1 with a spatially dependent value.

}

spot(i):min(i-floor(i),ceil(i)-i)*if(i-floor(i)-(ceil(i)-i),1,-1);
darea = A3*A3*PI;
area = darea/A1;
ug = sqrt(2*area/A2);
vg = ug*A2;

UVn = if(and(sq(Nx)+sq(Ny)-FTINY,sq(Nz)-FTINY),sin(atan(sqrt(sq(Nx)+sq(Ny))/Nz)),1);
x = 2*spot(U*UVn/ug);
y = 2*spot(V*UVn/vg)*A2;
r = 2*A3/ug;
xi = 2*spot(U*UVn/ug+.5);
yi = 2*spot(V*UVn/vg+.5)*A2;
xo =U*UVn/ug;
yo =V*UVn/vg;
refl = if(and(sq(x)+sq(y)-sq(r),sq(xi)+sq(yi)-sq(r)),0,1);

rxy = sq(x)+sq(y);
rixy = sq(xi)+sq(yi);
uper = if(rxy-sq(r),0,if(rxy-sq(r*.75),x,0))+if(rixy-sq(r),0,if(rixy-sq(r*.75),xi,0));
vper = if(rxy-sq(r),0,if(rxy-sq(r*.75),y,0))+if(rixy-sq(r),0,if(rixy-sq(r*.75),yi,0));
zper = 1;
mag = sqrt(sq(uper)+sq(vper)+sq(zper));

pv(i) =select(i,uper/mag,vper/mag,zper/mag);
nv(i) = select(i,Nx,Ny,Nz);
og(i) = select(i,0,0,1);
a(i) = select(i,cross(1,nv,og),cross(2,nv,og),cross(3,nv,og));
b = Acos(nv(3));
xcor = pv(1)*cos(b)+cross(1,a,pv)+a(1)*dot(a,pv)*(1-cos(b));
ycor = pv(2)*cos(b)+cross(2,a,pv)+a(2)*dot(a,pv)*(1-cos(b));
zcor = pv(3)*cos(b)+cross(3,a,pv)+a(3)*dot(a,pv)*(1-cos(b));


