function Q = affmat(phi,theta,b)
st=sin(theta);ct=cos(theta);
sp=sin(phi);cp=cos(phi);
Q(1,1)=-ct;    Q(1,2)= st;    Q(1,3)=0; 
Q(2,1)=-st*cp; Q(2,2)=-ct*cp; Q(2,3)=-sp;
Q(3,1)=-st*sp; Q(3,2)=-ct*sp; Q(3,3)=cp;
Q(1:3,4) = b*Q(1:3,1);
Q(4,1:3)=0; 
Q(4,4)=1;
