I have code where you give the 2 points a(x1,y1) and b(x2,y2) so that it calculates the angle between (alpha) them as shown in the image below:

[![enter image description here](https://i.stack.imgur.com/G5fz2.png)](https://i.stack.imgur.com/G5fz2.png)

I tried using this: `angle = math.degrees(math.atan2((x1 - x2),(y1 - y2)))`
to calculate the angle but it wont give the corrct value when the angle coordinates are like this in the image below:

[![enter image description here](https://i.stack.imgur.com/LFDH0.png)](https://i.stack.imgur.com/LFDH0.png)

I need a function that can always get the accurate value of the angle when given the coordinates

y2 can be greater than or less than y1 but x2 should always be greater than x1