I'm trying to find the direction of a moving object and I came across the concept of using atan2 to do this (if the angle is > 180, then it moves in the opposite direction). I read the Wikipedia article which states : The function atan2 (y,x) is defined as the angle in the Euclidean plane, given in radians, between the positive x axis and the ray to the point (x, y) ≠ (0, 0).
I'm having difficulty understanding how the angle between two points would be calculated using atan2. Can someone explain this with a visual example?
Edit: I'm calculating the angle in Python using the following code which calculates the clockwise angle between two points:
import numpy as np
def angle_between(p1, p2):
x = 0
ang1 = np.arctan2(*p1[::-1])
ang2 = np.arctan2(*p2[::-1])
return np.rad2deg((ang1 - ang2) % (2 * np.pi))
```