Java Data Type Tutorial - Java Math.atan2(double y, double x)








Syntax

Math.atan2(double y, double x) has the following syntax.

public static double atan2(double y,  double x)

Example

In the following code shows how to use Math.atan2(double y, double x) method.

// ww  w  .  ja va2  s  .c o m

public class Main {

   public static void main(String[] args) {

      // get a variable x which is equal to PI/2
      double x = Math.PI / 2;

      // get a variable y which is equal to PI/3
      double y = Math.PI / 3;

      // convert x  and y to degrees
      x = Math.toDegrees(x);
      y = Math.toDegrees(y);

      // get the polar coordinates
      System.out.println("Math.atan2(" + x + "," + y + ")=" + Math.atan2(x, y));

   }
}

The code above generates the following result.