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 .jav  a 2s.c om*/

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.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable