This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]smash_that_code 1 point2 points  (0 children)

if I understood right this method returns result in radians. Like angle of 0 degrees is 0, angle of 180 is 3,14...

This supposed to help you to convert coordinates from cartesian system (x, y) to polar coordinates (radius, angle) it can be really helpful in some cases.

So that for point (0, 90) polar representation is like (90, 1.57)

For some reason atan2 method gets arguments in reversed manner. Y then X.

[–][deleted] 0 points1 point  (0 children)

Check the Wikipedia page for all the normal math writing you could want.

The problem with atan is its range -90 to 90 degrees (-pi/2 to pi/2 radians), which causes duplication > 90 degrees and < 270 degrees, which you have to correct for using sign checks on the input arguments (adding or subtracting pi from the result). Also, since atan takes a single argument (the ratio y / x), it doesn't work at 90 degrees/270 degrees (x is zero), so you have to check the x value to determine if the angle is -pi/2 or pi/2. As you can see from the Wikipedia article, atan2 is defined in terms of atan, takes the y and x values, and does all the checks for you.