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}?
Asked
Active
Viewed 331 times
1
1 Answers
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
findInter[{p1_, p2_}, {p3_, p4_}] := t p1 + (1 - t) p2 /. Solve[t p1 + (1 - t) p2 == t1 p3 + (1 - t1) p4, {t, t1}][[1]]; findInter[{{1, 0}, {-1, 0}}, {{0, 1}, {1, 2}}]– Dr. belisarius Apr 07 '15 at 18:03f[t_, l_] := First@l - Subtract @@ l t; findInter[l1_, l2_] := f[t, l1] /. Solve[f[t, l1] == f[t1, l2]]; findInter[{{1, 0}, {-1, 0}}, {{0, 1}, {1, 2}}]– Dr. belisarius Apr 07 '15 at 18:58