0
votes

Let in a 2D problem you are given with slopes of two lines say (m1 & m2).

Now, how should I know what the angle between the two lines is?

I tried like this:

from math import atan
from math import degrees
from operator import abs
if 1+m1*m2:
    alpha = degrees(atan(abs((m1-m2)/(1+m1*m2)))
    print(alpha)
else:
    print(90)

Now, The problem is how to know which angle the code is going to print

enter image description here

Whether it is going to be alpha or beta It also prints -ve angle also?

While I only want alpha & I'll keep varying point D in +ve quadrant.

1

1 Answers

0
votes

Slopes don't contain full information about line direction (two directions are possible), so it is hard to decide what angle is needed (alpha or 180-alpha) in your case. Moreover, slope usage is limited, because vertical line has no legal slope value.

Perhaps it would be wise to use direction vectors for lines, in this case

atan2(d1 x d2, d1.dot.d2) 

gives signed angle needed to rotate d1 to d2.

But how are you going to use this angle?