function p = my_triangulation(d1,d2,t1,t2)
% This function performs triangulation to obtain
% the coordinates of a point p in the 3D space using
% the observation directions from two cameras.
% 
% Syntax:
%   p = my_triangulation(d1,d2,t1,t2)
%
% See Also:
% my_homography, my_Kest, my_camera_pose
    
    p = zeros(size(d1));
    for k = 1:size(d1,2)
        A  = [d1(:,k), -d2(:,k)];
        T  = A\(t2 - t1);
        p1 = t1 + T(1)*d1(:,k);
        p2 = t2 + T(2)*d2(:,k);
        p(:,k) = (p1 + p2)/2;
    end
end
