.atan2()

StevenSwiniarski's avatar
Published Jul 20, 2021Updated Aug 24, 2022
Contribute to Docs

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

Syntax

Math.atan2(y, x)

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

Example

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
}
}

All contributors

Contribute to Docs

Learn Java on Codecademy