Math Methods: atan2()

By: Dusty Arlia
Published on Saturday, March 29, 2014, 07:02 PM
Last Updated on Sunday, July 05, 2015 at 4:13 PM
Total Updates: 2

The atan2() method of the Math JavaScript object computes the angle from the X axis to a point. This method computes the arc tangent of the ratio y/x. The y argument is the Y coordinate of a point. The x argument is the x coordinate of a point. The coordinates are passed in the order "rise" over "run" (y the x or y/x). Here is its syntax:

Math.atan2(y, x)

The y argument is the Y coordinate of the point and the x argument is the X coordinate of the point. This method will return a value between -π and π radians. This value specifies the counterclockwise angle between the positive X axis and the point (x,y).