What is the best way to find the angle between the Blue and Green lines in this image?
The Blue line is straight, but the Green line is slightly tilted.
Green line coordinates are [(923, 286), (1495, 306)]
.
Blue line coordinates are [(901, 259), (901, 197)]
.
Here is my code of to calculate the angle:
def find_angle(A, B):
# Calculate the slope of line A
slope_A = (A[1][1] - A[0][1]) / (A[1][0] - A[0][0])
# Calculate the slope of line B
slope_B = (B[1][1] - B[0][1]) / (B[1][0] - B[0][0])
# Calculate the angle between the lines
print(slope_A,slope_B)
angle = math.atan2(slope_B, slope_A)
# Convert the angle from radians to degrees
print(angle)
angle_degrees = angle * 180 / math.pi
return angle_degrees
My calculation result is 90 or 89, but the Green line is a little bit tilted, so the angle should be 91 or 93.
Here's another image.
What is the problem with my code and how to improve that?