2 added 544 characters in body
source | link

Given

line1 = {p1, p2}; line2 = {p3, p4};

you could define two points on these lines:

l1 = {1 - u1, u1}.line1;
l2 = {1 - u2, u2}.line2;

and just solve for the intersection:

l1 /. Solve[l1 == l2, {u1, u2}]

Alternatively (and more elegantly) you could use projective geometry, where Cross[p1,p2] is the line between two points p1 and p2 and Cross[l1,l2] is the intersection between two lines l1 and l2:

euclidean2homogenous = Append[#, 1] &;
homogenous2euclidean = #[[;; -2]]/#[[-1]] &;

line1 = Cross[euclidean2homogenous@p1, euclidean2homogenous@p2];
line2 = Cross[euclidean2homogenous@p3, euclidean2homogenous@p4];

intersection = Cross[line1, line2]

homogenous2euclidean[intersection]

Given

line1 = {p1, p2}; line2 = {p3, p4};

you could define two points on these lines:

l1 = {1 - u1, u1}.line1;
l2 = {1 - u2, u2}.line2;

and just solve for the intersection:

l1 /. Solve[l1 == l2, {u1, u2}]

Given

line1 = {p1, p2}; line2 = {p3, p4};

you could define two points on these lines:

l1 = {1 - u1, u1}.line1;
l2 = {1 - u2, u2}.line2;

and just solve for the intersection:

l1 /. Solve[l1 == l2, {u1, u2}]

Alternatively (and more elegantly) you could use projective geometry, where Cross[p1,p2] is the line between two points p1 and p2 and Cross[l1,l2] is the intersection between two lines l1 and l2:

euclidean2homogenous = Append[#, 1] &;
homogenous2euclidean = #[[;; -2]]/#[[-1]] &;

line1 = Cross[euclidean2homogenous@p1, euclidean2homogenous@p2];
line2 = Cross[euclidean2homogenous@p3, euclidean2homogenous@p4];

intersection = Cross[line1, line2]

homogenous2euclidean[intersection]
1
source | link

Given

line1 = {p1, p2}; line2 = {p3, p4};

you could define two points on these lines:

l1 = {1 - u1, u1}.line1;
l2 = {1 - u2, u2}.line2;

and just solve for the intersection:

l1 /. Solve[l1 == l2, {u1, u2}]