JavaScript & jQuery Tutorials

JS Home Right Arrow JS Reference Right Arrow Math Right Arrow atan2()

atan2()  Math  class method

Description

Returns a numeric radians value between -PI and PI representing the anticlockwise angle theta of an (x,y) point.

  • Radians to Degrees - divide number by (Math.PI / 180).
  • Degrees to Radians - multiply number by (Math.PI * 180).
  • Like all class methods atan2() should be used on the class rather than an instance of the class.

Syntax


Signature Description
Math.atan2(y,x)Returns a numeric radians value between -PI and PI representing the anticlockwise angle theta of an (x,y) point.

Parameters


Parameter Description
yy-axis coordinate:
  • Non-numeric strings returns NaN.
  • Passing no parameter returns NaN.
  • Passing null returns 0.
xx-axis coordinate:
  • Non-numeric strings returns NaN.
  • Passing no parameter returns NaN.

Examples

The code below displays atan2() usage.



// Store results in an array.
var atan2Values = new Array(10);
atan2Values[0] = Math.atan2(-7,2);
atan2Values[1] = Math.atan2(7,-2);
atan2Values[2] = Math.atan2(0,5);
atan2Values[3] = Math.atan2(5,0);
atan2Values[4] = Math.atan2('0.75','2');
atan2Values[5] = Math.atan2('a string',6);
atan2Values[6] = Math.atan2(6,'a string');
atan2Values[7] = Math.atan2();
atan2Values[8] = Math.atan2(null,4);
atan2Values[9] = Math.atan2(4,null);

alert(atan2Values);  

Press the button below to action the above code:



Related Tutorials

JavaScript Advanced Tutorials - Lesson 4 - Math




  

go to home page Homepage go to top of page Top