Easy Tutorial
❮ Arrays Fill Collection Reverse ❯

Java atan2() Method

Java Number Class


The atan2() method is used to convert rectangular coordinates (x, y) into polar coordinates (r, theta), returning the resulting angle theta. This method calculates the angle theta by computing the arctangent of y/x, with the range from -pi to pi.

Syntax

double atan2(double y, double x)

Parameters

Return Value

The theta component of the polar coordinates (r, theta) corresponding to the point (x, y) in Cartesian coordinates.

Example

public class Test{ 
    public static void main(String args[]){
        double x = 45.0;
        double y = 30.0;

        System.out.println( Math.atan2(x, y) );
    }
}

Compiling the above program will output:

0.982793723247329

Java Number Class

❮ Arrays Fill Collection Reverse ❯