Algorithm for intersection of 2 lines?

后端 未结 3 1793
死守一世寂寞
死守一世寂寞 2020-11-29 23:50

I have 2 lines. Both lines containing their 2 points of X and Y. This means they both have length.

I see 2 formulas, one using determinants and one using normal alge

3条回答
  •  醉酒成梦
    2020-11-30 00:31

    Assuming you have two lines of the form Ax + By = C, you can find it pretty easily:

    float delta = A1 * B2 - A2 * B1;
    
    if (delta == 0) 
        throw new ArgumentException("Lines are parallel");
    
    float x = (B2 * C1 - B1 * C2) / delta;
    float y = (A1 * C2 - A2 * C1) / delta;
    

    Pulled from here

提交回复
热议问题