Java atan2() Method
The atan2() method converts rectangular coordinates (x, y) into polar coordinates (r, theta) and returns the resulting angle theta. The method computes the phase angle theta by calculating the arc tangent of y/x, in the range from -pi to pi.
Syntax
double atan2(double y, double x)
Parameters
-
y -- the ordinate (y coordinate).
-
x -- the abscissa (x coordinate).
Return Value
The theta component of the polar coordinate point (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 is:
0.982793723247329
The Java Number class