found a simple solution ... It comes from high school math! First make the equation of the line made from the origin and the initial position of the form y = mx+c . A point lying on either side of this line will satisfy y < mx+c or y > mx+c , depending on where it is located. If you find the angles clockwise or counterclockwise, do the following check:
currentPosition.y < (currentPosition.x *(initialPosition.y - origin.y) + (initialPosition .x * origin.y - initialPosition.y * origin.x)) / (initialPosition.x - origin.x)
If the above condition is true, then the line formed from the beginning and the current position makes an angle less than 180 degrees (clockwise) with the line formed from the beginning and the starting position. Otherwise, the tilt angle is more than 180 degrees clockwise and less than 180 degrees counterclockwise ... and so on. Depending on the requirement, the final angle is either (angle returned by acos) or (360 - (angle returned by acos)) .
source share