% J. Kosecka, GMU 2004
function [XP,lambda] = computeStructure(p, q, R, T);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% given the projection matrix between 1st and 2nd view (assuming 1st view is [I,0])
% compute the unknown scale lambda's with respect to the first frame 
% and 3D structure with respect to 1st and 2nd frame
nc = size(q, 2);
for k = 1:nc
 alpha(:,k) = -(skew(q(:,k))*T)'*(skew(q(:,k))*R*p(:,k))/(norm(skew(q(:,k))*T))^2;
end
lambda = 1./alpha;
XP(:,:,1) = [lambda.*p(1,:); lambda.*p(2,:); lambda.*p(3,:)];
tt = [R, T; 0 0 0 1]*[XP(:,:,1); ones(1,nc)];
XP(:,:,2) = tt(1:3,:);

        
