% Some simple tests of p2angle

% -- Construct two spaces that are overlapping at 45 degrees

A = [1, 0;
0, 1;
0, 0;
0, 0];

B = [1, 0;
0, 0;
1, 0;
0, 1];

[Q,R] = qr(rand(4));
A = Q*A; % This doesn't change the angles, but scrambles things some
B = Q*B;

[x,y] = p2angle(A,B);
cxy1 = abs( (A*x)'*(B*y) )/norm(A*x)/norm(B*y);
fprintf('Test 1: sqrt(1/2)-cos(theta): %g\n', sqrt(1/2)-cxy1);

% -- See if overlapping spaces have zero angle

n = 20;
m = 10;
p = 11;

A = randn(n,m);
B = randn(n,p);

[x,y] = p2angle(A,B);
cxy = abs( (A*x)'*(B*y) )/norm(A*x)/norm(B*y);
fprintf('Test 2: 1-cos(theta): %g\n', 1-cxy);