Calculating the angle between two lines without having to calculate the slope? (Java)

后端 未结 8 1247
夕颜
夕颜 2020-11-28 07:27

I have two Lines: L1 and L2. I want to calculate the angle between the two lines. L1 has points: {(x1, y1), (x2, y2)} and L2 has points: {(x3, y3), (x4, y

8条回答
  •  广开言路
    2020-11-28 07:29

    The formula for getting the angle is tan a = (slope1-slope2)/(1+slope1*slope2)

    You are using:

    tan a = (slope1 - slope2) / (1 - slope1 * slope2)
    

    So it should be:

    double angle = Math.atan((slope1 - slope2) / (1 + slope1 * slope2));
    

提交回复
热议问题