java.lang.Math.atan2() in Java


atan2() is an inbuilt method in Java which is used to return the theta component from polar coordinate. The atan2() method returns a numeric value between –\pi and \pi representing the angle \theta of a (x, y) point and 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

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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(x, y);
  
        System.out.println(theta);
    }
}

chevron_right


Output :

1.4056476493802699


My Personal Notes arrow_drop_up

Striver(underscore)79 at Codechef and codeforces D

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.