Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java atan2() Method

Java atan2() Method

Java Number ClassThe Java Number class


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

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


Java Number ClassThe Java Number class