Thursday, July 23, 2026
HomeLanguagesJavajava.lang.Math.atan2() in Java

java.lang.Math.atan2() in Java

atan2() is an inbuilt method in Java that is used to return the theta component from the polar coordinate. The atan2() method returns a numeric value between –\pi  and \pi  representing the angle \theta  of a (x, y) point and the positive x-axis. It is the counterclockwise angle, measured in radian, between the positive X-axis, and the point (x, y). 
Syntax : 
 

Math.atan2(double y, double x)
where, x and y are X and Y coordinates in double data type.

Returns : 
It returns a double value. The double value is \theta  from polar coordinate (r, theta). 
Example: Program demonstrating the atan2() method 
 

Java




// Java program for implementation of
// atan2() method
import java.util.*;
class GFG {
 
    // Driver Code
    public static void main(String args[])
    {
 
        // X and Y coordinates
        double x = 90.0;
        double y = 15.0;
 
        // theta value from polar coordinate (r, theta)
        double theta = Math.atan2(y, x);
 
        System.out.println(theta);
    }
}


Output

0.16514867741462683
RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6902 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6971 POSTS0 COMMENTS