Java atan2() method
atan2() method is used to convert rectangular coordinates (x, y) into polar Coordinates (r, theta), returns the resulting angle theta. This method calculates the phase angle theta by calculating the arctangent of y/x, ranging from -pi to pi.
Syntax
double atan2(double y, double x)
Parameters
y -- Vertical coordinate.
#x -- Abscissa.
Return value
The theta component of the polar coordinate midpoint (r, theta) corresponding to the Cartesian coordinate midpoint (x, y).
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 and the output result is:
0.982793723247329