# Ruby | Math atan2() function

The atan2() is an inbuilt function in Ruby returns angent inverse of (y/x), where y is the proportion of the y-coordinate and x is the proportion of the x-coordinate. The numeric value lies 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(y, x)

Parameters: The function accepts x and y coordinates.

Return Value: It returns returns a numeric value between –pi and +pi representing the angle theta of a (x, y) point and positive x-axis

Example 1:

 `#Ruby program for atan2() function ` ` `  `#Assigning values ` `y1 = 10 x1 = 10 ` ` `  `    ``y2 ` `    ``= 15 x2 = 10 ` ` `  `#Prints the atan2() value ` `              ``puts` `Math.``atan2``(y1, x1) ` `                  ``puts` `Math.``atan2``(y2, x2) `

Output:

```0.7853981633974483
0.982793723247329
```

Example 2:

 `#Ruby program for atan2() function ` ` `  `#Assigning values ` `y1 = 10 x1 = 5 ` ` `  `    ``y2 ` `    ``= 29 x2 = 17 ` ` `  `#Prints the atan2() value ` `              ``puts` `Math.``atan2``(y1, x1) ` `                  ``puts` `Math.``atan2``(y2, x2) `

Output:

``` 1.1071487177940904
1.0405805540182667
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

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.