function [ext_dist] = calc_pairwise_dist_proj1(A1, A2, lowdim, P1); 

len = round(size(A1,2)/lowdim);
dist = (1:len)*0.0;
imdim = size(A1,1); 
P2 = calc_projection_mat(A2, lowdim);
for j=0:(len-1),
  dist1 = 0.0;
  for i=1:len,
    k = mod(i + j-1, len)+1;
    k1 = mod(k,len)+1;
    i1 = mod(i,len)+1;
dist1 = dist1 + norm( (P1(:,((i1-1)*imdim+1):(i1*imdim))-P1(:,((i-1)*imdim+1):(i*imdim))) - (P2(:,((k1-1)*imdim+1):(k1*imdim))-P2(:,((k-1)*imdim+1):(k*imdim))),'fro');
  end
  dist(j+1) = sqrt(dist1/len);
end
ext_dist = min(min(dist));
%dist
[I J] = find(dist ==ext_dist);
if J ~= 1,
 disp([sprintf('The minimum angle is %d',J)]);
end

return;
% keyboard;
    






