function theta = angle2(r11,c11,r12,c12,r21,c21,r22,c22)
%
% angle2: Compute the smaller angle between two vectors
% On input:
%     r11,c11: first endpoint of first vector
%     r12,c12: second endpoint of first vector
%     r21,c21: first endpoint of second vector
%     r22,c22: second endpoint of second vector
% On output:
%     theta: angle between two vectors
% Calling sequence:
%     theta = angle2(r11,c11,r12,c12,r21,c21,r22,c22)

vr = r12-r11; vc = c12-c11;
wr = r22-r21; wc = c22-c21;

len1 = sqrt(vr^2+vc^2);
len2 = sqrt(wr^2+wc^2);

if abs(len1)<eps
  len1 = 1;
end;
if abs(len2)<eps
  len2 = 1;
end;
costheta = (vr*wr+vc*wc)/(len1*len2);
theta = acos(costheta);
