I've been calculating rotation needed between two 3d points, and I'm having some slight trouble.
You can use very basic sohcahtoa to find the angle needed between the two points by making a right triangle and just doing arctan of opposite/adjacent (the two sides). Now this only works if all of the values are positive, as, for example, arctan(-5/-4) == arctan(5/4). I do remember learning something about fixing this back when I learned about trig identities in school, and how to fix it, but my friend sent me some code, and he used Math.atan2 instead of tangent.
Now his code works perfectly, and was not too different from mine, and it really made me wonder what Math.atan2 does. I searched up on the internet, and didn't understand a word of the descriptions. Can someone show me what Math.atan2 is in normal math writing?
Math.java it define as
public static double atan2(double y, double x) {
return StrictMath.atan2(y, x); // default impl. delegates to StrictMath
}
and this will return the counter-clock wise angle with respect to X- axis.
If you interchange those two you will get the clock wise angle with respect to X- axis.
In Cartesian coordinate system we consider counter-clock wise angle with respect to X-axis. That is why Math.java use this as above.
Swapping the order of the arguments means that instead of the (counter-clockwise) angle with the X-axis you get the (clockwise) angle with the Y-axis. It's not wrong, just unusual.
Assuming you don't understand the difference of 360° and 2 Pi: There are different ways to express a distance on a circle's perimeter. An angle of 0° to 360° is probably the most common one, but in scientific notation, it is more common to use radians - which is a distance on the perimeter of the unit circle.
If you think of the unit circle (a circle with radius 1), you'll notice the perimeter is 2 Pi. If you only go around half the circle, the perimeter of that would be Pi - and you went from 0° to 180°. So all the notations that you mentioned in your question actually mean the same, just expressed in a different way.
atan2 returns a value between -Pi and +Pi (which covers 2 Pi and is thus a full circle) that can easily be converted to degrees using Math.toDegrees()
From the Javadoc for atan2:
public static double atan2(double y, double x)
Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi.
not sure where the confusion lies (it seems the linked SO Answer is wrong)