Celestial Programming : Intersection of Two Lines (2D)

Lines can be expressed in a few different foms, which one is most convenient often depends on the information available to compute them. Provided are the equations to compute the intersection of two lines for several different equation forms. The slope-intercept, and point-slope forms cannot represent vertical lines, since there is no way to represent infinite slope. But this case is trivial, as it means \(x\) is constant. So just plug \(x\) in to the other equation to solve for \(y\) directly. The two-point form can have cases where \(x_1 = x_2\) or \(x_3 = x_4\). Such a case is also trivial, as we can simply set \(x = x_1\) and use the other equation to solve for \(y\) directly.

The solution is given to compute the x coordinate, the y coordinate is computed using the value of x plugged in to any of the first equations.

\( (x, y) \) The computed coordinates of the intersection point.
\( (x_1, y_1) \) Coordinates of the first point.
\( (x_2, y_2) \) Coordinates of the second point.
\( m \) Slope of line \( \frac{rise}{run} \).
\( m_1 \) Slope of line 1.
\( m_2 \) Slope of line 2.

Slope-Intercept Form

Given two equations of the form: $$ y = m_1 x + b_1 \\ y = m_2 x + b_2 $$ The x intersection point is: $$ x=\frac{b_2 - b_1}{m_1 - m_2} $$


Point-Slope Form

Given two equations of the form: $$ y = m_1(x - x_1) + y_1 \\ y = m_2(x - x_2) + y_2 $$ The x intersection point is: $$ x = \frac{y_1 - y_2 + m_2 x_2 - m_1 x_1}{m_2 - m_1} $$


Two Point Form

Given two equations of the form: $$ y = \frac{y_2 - y_1}{x_2 - x_1}(x - x_1) + y_1 \\ y = \frac{y_4 - y_3}{x_4 - x_3}(x - x_3) + y_3 $$ The x intersection point is: $$ x = \frac{y_1 - y_3 + \frac{y_4 - y_3}{x_4 - x_3}x_3 - \frac{y_2 - y_1}{x_2 - x_1}x_1} {\frac{y_4 - y_3}{x_4 - x_3} - \frac{y_2 - y_1}{x_2 - x_1}} $$ If \(x_1 = x_2\) use \(x=x_1\) in the second equation to solve for \(y\) directly. Similarly if \(x_3 = x_4\) use \(x=x_3\) in the first equation.


Standard Form

Given two equations of the form: $$ a_1x + b_1y + c_1 = 0 \\ a_2x + b_2y + c_2 = 0 $$ The solution is: $$ x = \frac{b_1 c_2 - b_2 c_1}{a_1 b_2 - a_2 b_1} $$ $$ y = \frac{c_1 a_2 - c_2 a_1}{a_1 b_2 - a_2 b_1} $$

Slope Intercept Form
Line 1


Line 2


Point Slope Form
Line 1



Line 2



Two Point Form
Line 1




Line 2




Standard Form
Line 1



Line 2