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:
Output:
0.7853981633974483
0.982793723247329
Example 2:
Output:
1.1071487177940904
1.0405805540182667
Reference:
https://devdocs.io/ruby~2.5/math#method-c-atan2Ruby