calculate angle between 3 points python

Solutions on MaxInterview for calculate angle between 3 points python by the best coders in the world

showing results for - "calculate angle between 3 points python"
Filippo
23 Oct 2017
1from math import atan2, pi
2
3def angle(A, B, C, /):
4    Ax, Ay = A[0]-B[0], A[1]-B[1]
5    Cx, Cy = C[0]-B[0], C[1]-B[1]
6    a = atan2(Ay, Ax)
7    c = atan2(Cy, Cx)
8    if a < 0: a += pi*2
9    if c < 0: c += pi*2
10    return (pi*2 + c - a) if a > c else (c - a)
11