I struggle with this in JavaScript, but this problem applies to many other languages ββ/ environments.
I want one object to rotate in the direction of another object, and I use:
atan2(obj1.dy, obj1.dx) - obj2.getRotation()
to check whether the second object should rotate clockwise or counterclockwise at a given time.
In KineticJS, the JS / HTML5 / Canvas programming environment that I use, the angle is specified in radians from 0 to 2 pi, starting from the positive Y axis and going clockwise. This behavior is also observed in many other programming environments.
However, when calculating the angle of movement from the second object using the Math.atan2 (y, x) function , the angle is determined from -pi to pi, starting with the positive X axis, going counterclockwise.
To clarify:

Question:
How can I calculate the angle in normal radians from the result of the atan2 () function?
source share