Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript Math atan2( ) Method

  • Last Updated : 23 Nov, 2020

Below is the example of the Math atan2() Method. 

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

  • Example: When y-coordinate is greater than x-coordinate: 

Javascript




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

Output: 

1.4056476493802699

The Math.atan2() method 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 the 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 method accepts two parameters as mentioned above and described below:  

  • value1: This parameter represents the y-coordinate.
  • value2: represents x-coordinate of the point (x,y).

Returns: It returns the arctangent of the quotient of its arguments.

Below examples illustrate the Math.atan2() method in JavaScript:  

  • Example 1: 
Input : Math.atan2(90, 15);  
Output : 1.4056476493802699
  • Example 2: 
Input : Math.atan2(15, 90);
Output : 0.16514867741462683

More codes for the above method are as follows:

Program 1: When y-coordinate is smaller than x-coordinate  

Javascript




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

Output: 

0.16514867741462683

Program 2: When y-coordinate is same as x-coordinate 

Javascript




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

Output: 

0.7853981633974483

Supported Browsers: 

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!