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

后端 未结 8 1228
夕颜
夕颜 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:45

    Check this Python code:

    import math
    def angle(x1,y1,x2,y2,x3,y3):
    
      if (x1==x2==x3 or y1==y2==y3):
        return 180
      else:
        dx1 = x2-x1
        dy1 = y2-y1
        dx2 = x3-x2
        dy2 = y3-y2
        if x1==x2:
          a1=90
        else:
          m1=dy1/dx1
          a1=math.degrees(math.atan(m1))
        if x2==x3:
          a2=90
        else:
          m2=dy2/dx2
          a2=math.degrees(math.atan(m2))
        angle = abs(a2-a1)
        return angle
    
    print angle(0,4,0,0,9,-6)
    

提交回复
热议问题