Inner angle between two lines

前端 未结 8 1292
忘掉有多难
忘掉有多难 2020-12-14 20:17

I have two lines: Line1 and Line2. Each line is defined by two points (P1L1(x1, y1), P2L1(x2, y2) and P1L1(x1, y1), P2L3(x2, y3)). I want to know t

8条回答
  •  失恋的感觉
    2020-12-14 20:50

    The whole point is much easier than the given answers:

    When you use atan(slope) you lose (literally) one bit of information, that is there are exactly two angles (theta) and (theta+PI) in the range (0..2*PI), which give the same value for the function tan().

    Just use atan2(deltax, deltay) and you get the right angle. For instance

    atan2(1,1) == PI/4
    atan2(-1,-1) == 5*PI/4
    

    Then subtract, take absolute value, and if greater than PI subtract from 2*PI.

提交回复
热议问题