JavaScript | Math.atan2( )

The Math.atan2() function in JavaScript is used to return the arctangent of the quotient of its arguments. The Math.atan2() method returns a numeric value between -Π and Π representing the angle theta of an (x, y) point and positive x axis. This is the counterclockwise angle, measured in radians, between the positive X axis, and the point (x, y).

Syntax:

Math.atan2(value1, value2)

Parameters: This function accepts two parameters value1 and value2. value1 represents the y-coordintae and value2 represents x-coordinate of the point (x,y).

Return Value: It returns the arctangent of the quotient of its arguments.

Examples:



Input : Math.atan2(90, 15);  
Output : 1.4056476493802699

Input : Math.atan2(15, 90);
Output : 0.16514867741462683

Below programs illustrate the Math.atan2() function in JavaScript:

  1. When y-coordinate is greater than x-coordinate:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script type="text/javascript">
       document.write(Math.atan2(90, 15));  
    </script>

    chevron_right

    
    

    Output:

    1.4056476493802699
  2. When y-coordinate is smaller than x-coordinate
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script type="text/javascript">
       document.write(Math.atan2(15, 90));  
    </script>

    chevron_right

    
    

    Output:

    0.16514867741462683


My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

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 :

Be the First to upvote.


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