//mirror deflection plots
//increasing phi = reflection moving upwards, increasing theta = reflection moving CCW from above
msl=25; //mm mirror side length {15,20,25}
//for 1 to 3 mirrors at +-45 deg theta acceptance
//  window sizes are:
//    3.79x5.5 mm full or 3.79x6.9 with small triangle at bottom
//    5.28x7.4 mm full or 5.28x11 with triangle
//    6.77x9.4 mm full or 6.77x14.1 with triangle
//for 4 mirrors at +-45 deg theta acceptance
//    no windows at any mirror size (theta split)
//for 1 to 3 mirrors at +-54 deg theta acceptance
//  window sizes are:
//    1.0x5.5 mm full
//    1.6x7.3 mm full
//    2.2x9.3 mm full
//for mirrors at +-60 deg theta acceptance
//    no windows at any mirror size (theta split)
//for 4 mirrors at +-30 deg theta acceptance
//    7.5x4.2 mm full
//    6.8x5.8 mm full
//    8.6x7.3 mm full

mth=1; //mm mirror thickness
pcl=sqrt((msl^2-mth^2)/12); //mm zero-torque centerline for mirror
//mcl=pcl+mth/2; //[mm] mirror reflective surface offset
mcl=msl/2+mth/2;  //for 4 mirrors

//2D plot of mirror from the side
if(%f)
phi=linspace(0,%pi/4,8);
tl=length(phi);
for i=1:tl
    p=phi(i);
    rmat=[cos(p),-sin(p);sin(p),cos(p)];
    pc=rmat*[mcl;0];
    vc=rmat*[0;1];
    pl=pc+(msl/2)*vc;
    pl(:,2)=pc-(msl/2)*vc;
    plot(pl(1,:),pl(2,:),'b')
end
isoview on;
end

//2D projection of mirror for a laser at theta=0 phi=0
if(%t)
mpts=[
mcl,mcl,mcl,mcl,mcl;
-msl/2,-msl/2,msl/2,msl/2,-msl/2;
-msl/2,msl/2,msl/2,-msl/2,-msl/2];
taa=30;//[deg] theta +- accentance angle
paa=45;//[deg] phi acceptance angle
pt=[
0,paa,paa,paa,0,0;
0,0,taa,-taa,taa,-taa];//[deg] phi in row 1, theta in row 2
nn=size(pt,2);
for(i=1:nn)
phi=pt(1,i)/180*%pi;
prm=[cos(phi),0,-sin(phi);0,1,0;sin(phi),0,cos(phi)];
theta=pt(2,i)/180*%pi;
trm=[cos(theta),-sin(theta),0;sin(theta),cos(theta),0;0,0,1];
mptsr=prm*mpts;
mptsr=trm*mptsr;
xp=mptsr(2,:);
yp=mptsr(3,:);
plot(xp,yp,'color',i);
end
isoview on;
end
