tscript2

Test triangulare formula (3D)

p1 = [3 8 4];
k1 = [1 2 -3];
k1 = k1/norm(k1);

p2 = [-4 4 -8];
k2 = [3 -2 1];
k2 = k2/norm(k2);
b = [ dot(p2-p1,k1); -dot(p2-p1,k2)];
A = [dot(k1,k1) -dot(k1,k2); -dot(k1,k2) dot(k2,k2)];
q = A\b;

pA = p1+k1*q(1)
pB = p2+k2*q(2)
pA =

    4.0778   10.1556    0.7667


pB =

    0.4333    1.0444   -6.5222

qrng = [-10 10];
p = ones(2,1)*p1+qrng'*k1;
plot3(p(:,1),p(:,2),p(:,3),'b');
hold on
p = ones(2,1)*p2+qrng'*k2;
plot3(p(:,1),p(:,2),p(:,3),'g');
hold off

hold on
plot3([pA(1) pB(1)],[pA(2) pB(2)],[pA(3) pB(3)],'mo-');
hold off