The Math.atan2() method returns the counterclockwise angle, in radians, between a (x,y) point and the positive x-axis.


Math.atan2(y, x)

Note that the order of arguments is first the Y coordinate, then the X coordinate.


Use Math.atan2() to return the angle of point (0.0, 1.0) and the x-axis:

public class Main {
public static void main(String[] args) {
double x = 0.0;
double y = 1.0;
System.out.println(Math.atan2(y, x));
// Output: 1.5707963267948966


Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Java on Codecademy