Computing the Intersection of Two Lines

Two lines ax + by + c = 0 and dx + ey + f = 0 intersect when ax + by + c = dx + ey + f. We can solve for x and y in terms of the coefficients as follows. First, solve for x:

(1)   \begin{align*}ax + by + c &= 0\\ax &= -by - c\\ x &= \frac{-by - c}{a}.\end{align*}

Second, plug the solution into the second line equation:

(2)   \begin{align*}d\left(\frac{-by - c}{a}\right) + ey + f &= 0\\ \frac{-bdy - cd}{a} + ey + f &= 0\\ -bdy-cd+aey+af &= 0\\ aey-bdy &= cd-af\\ y(ae-bd) &= cd-af\\ y &= \frac{cd-af}{ae-bd}.\end{align*}

Repeat this process, solving for y first, to obtain an expression for x:

(3)   \begin{align*}ax + by + c &= 0\\by &= -ax - c\\ y &= \frac{-ax - c}{b}.\end{align*}

Plug the solution into the second line equation:

(4)   \begin{align*}dx + e\left(\frac{-ax - c}{b}\right) + f &= 0\\ dx + \frac{-aex - ce}{b} + f &= 0\\ bdx-aex-ce+bf &= 0\\ bdx-aex &= ce-bf\\ x(bd-ae) &= ce-bf\\ x &= \frac{ce-bf}{bd-ae}.\end{align*}

Note that the denominators of both coordinates are the same modulo sign, so we can multiply either by -1/-1 to normalize the denominator and make its calculation reusable (below we apply this to y). This leaves us with the final expression:

(5)   \begin{align*}(x, y) &= \left(\frac{ce-bf}{bd-ae}, \frac{af-cd}{bd-ae}\right).\end{align*}

The following demo allows you to specify two lines via two points each and observe the intermediate intersection point calculations.







  • intX numerator:
  • intX denominator:
  • intY numerator:
  • intY denominator:

1 thought on “Computing the Intersection of Two Lines

  1. Pingback: Finding the largest area axis-parallel square with a known center in a polygon | Clinton Freeman

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.