Java atan2() Method
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 phase angle theta by computing the arctangent of y/x, in the range from -pi to pi.
Syntax
double atan2(double y, double x)
Parameters
y-- Ordinate.
x-- Abscissa.
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) );
}
}
Compile the above program, the output result is:
0.982793723247329
Other Extensions
Java Number Class