1

What is the easiest way to find the crossing point of two intersecting lines passing lets say through points line1 = {p1,p2}, line2 = {p3,p4}?

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
na4
  • 19
  • 1

1 Answers1

4

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]
Niki Estner
  • 36,101
  • 3
  • 92
  • 152