-2

I need to find the intersection point of two infinite lines on a 2D plane. In my code, the lines are represented by

  • the coordinates of a point I know is on the line.
  • a vector.

I'm interested in a CPU efficient algorithm to find the intersection point.

I tried starting from the answers to this question: Determining if two rays intersect , but I don't know how to adapt it for lines that are infinite in both directions, and to get the actual intersection point.

P. Oring
  • 9
  • 3
  • What about the answer to that question did you not understand? Just don't exclude intersections with negative u/v. – Sneftel Apr 29 '18 at 10:25
  • 3
    This is a pretty simple operation. It is rather hard to make it CPU inefficient. – Yves Daoust Apr 29 '18 at 10:26
  • Convert vector form to cartesian equation for each line then solve a simultaneous equation for intersection point (if it exists) – mathematician1975 Apr 29 '18 at 10:27
  • "intersection of two lines stack overflow" Google search finds more than 10 similar questions with answers. What makes your question unique? – kfx Apr 29 '18 at 11:41

1 Answers1

-1

Solve the 2x2 system

X Uy - Y Ux = Px Uy - Py Ux
X Vy - Y Vx = Qx Vy - Qy Vx
Yves Daoust
  • 53,540
  • 8
  • 41
  • 94