Java .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.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours

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

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours