How to find a point where $L_1$ and $L_2$ intersect, given that $L_1$ goes through $(x_1,y_1)$ and it's slope is $\alpha_1$ and $L_2$ goes through $(x_2,y_2)$ and it's slope is $\alpha_2$? I tried applying sine theorem but I get two answers instead of one. Doing to Cartesian coordinates complicates things (vertical and horizontal lines should be differently to avoid division by zero in $\dfrac{1}{\sin(\alpha)}$ and $\dfrac{1}{\cos(\alpha)}$ cases.

  • $\begingroup$ It seems that the point of intersection can be found by solving the two equations obtained through point-slope form. $\endgroup$
    – Mick
    Oct 30, 2016 at 12:55
  • $\begingroup$ @Mick Thank you for rephrasing my question. I am learning Python at a moment, not math. My easiest bet is to attach a solver and be done with it. I am looking for a cleaner approach. I tried Cartesian coordinate system, but it produces special cases (like vertical line cannot be expressed in the form y=ax+b). Is there a standard formula to solve it? $\endgroup$
    – Stepan
    Oct 30, 2016 at 14:45
  • $\begingroup$ lol, you have already asked this. $\endgroup$
    – Anonymous
    Oct 30, 2016 at 16:55
  • $\begingroup$ I really don't understand why don't you just do $\mbox{if}(\alpha_i = \infty)\mbox{else formula} $ the efficiency of this is $O(1)$ $\endgroup$
    – Anonymous
    Oct 30, 2016 at 16:58
  • $\begingroup$ Statements like if(!ALPHA==PI/2){... are meaningless. One shouldn't compare two doubles unless this is a symbolic computation.For this problem I will use distance to line from the origin + angle ((infinity,0)(origin),(point closest to origin)) to represent the line, because it have these problems. $\endgroup$
    – Stepan
    Oct 30, 2016 at 20:56

2 Answers 2


Initially, we have $L_1: y – y_1 = m_1(x – x_1)$ and $ L_2: y – y_2 = m_2(x – x_2)$.

If they intersect at (h, k), then just combine the two equations to get $ m_1(h – x_1) + y_1 = m_2(h – x_2) + y_2$

Finally, $h = \dfrac {(m_2x_2 – m_1x_1) – (y_2 – y_1)}{m_2 – m_1}$

$k$ can be found by substituting the value of $h$ back in $L_1$.


The following cases should be checked before applying the formula.

1) If $m_1 = 0$, then from $L_1$, $k = y_1$ and h can be found using $L_2$.

2) If $m_2 = 0$, then ....

3) If $m_1 = 0$ and $m_2 = 0$, then either they never meet or meet at infinitely many points.

4) If $m_1 = \infty$ (i.e. $L_1: x = x_1$), then simply $h = x_1$, and k can be found accordingly.

5) If $m_2 = \infty$, then .....

6) If $m_1 = \infty$ and $m_2 = \infty$, then ......

7) If $m_1 – m_2 = 0$, this means the two lines are either parallel or actually the same line. In the first occasion, the point of intersection can never be found. In the second occasion, there are infinitely many points of intersection.


Years later I am writing this to answer the precise question that was asked (because I needed it). The solution given by Mick is correct, so I won't repeat his calculations.

The original question asked about lines given by angles, not by slopes. Also when programming, we have to be careful because the mod function is usually not the mathematical mod function.

At the end, I give a function in javascript (where % is the mod or remainder function). The logic does not need seven cases.

CASE 1: if the two angles are equal (mod 180 degrees), then the lines are parallel, and either you have infinite solutions or none at all. Either case is a problem, so we simply throw an error and stop.

CASE 2: Line 1 is vertical (angle1 mod 180 degrees is 90)

CASE 3: Line 2 is vertical

CASE 4: Normal case

The details can be seen from the program below (angles are input in degrees, but calculations are done in radians).

function xsect(x0, y0, a0, x1, y1, a1) {
    toRad = Math.PI / 180
    if ((((a0-a1) % 180) + 180) % 180 === 0) throw parallelError
    if (((a0 % 180) + 180) % 180 === 90) {
        // vertical line at x = x0
        return [x0, Math.tan(a1*toRad) * (x0-x1) + y1]
    else if (((a1 % 180) + 180) % 180 === 90) {
        // vertical line at x = x0
        return [x1, Math.tan(a0*toRad) * (x1-x0) + y0]
    let m0 = Math.tan(a0*toRad) // Line 0: y = m0 (x - x0) + y0
    let m1 = Math.tan(a1*toRad) // Line 1: y = m1 (x - x1) + y1
    let x = ((m0 * x0 - m1 * x1) - (y0 - y1)) / (m0 - m1)
    return [x, m0 * (x - x0) + y0]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.