atan2()  Math  class method JS Home  <<  JS Reference  <<  Math  <<  atan2()

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

JavaScript Basics

JavaScript Basics

JavaScript Intermediate

JavaScript Intermediate

JavaScript Advanced

JavaScript Advanced

JavaScript Reference

JavaScript Entities

Globals

Math

Class Properties
E
LN2
LN10
LOG2E
LOG10E
PI
SQRT1_2
SQRT2
Instance Properties
None.
Class Methods
abs()
acos()
asin()
atan()
atan2()
ceil()
cos()
exp()
floor()
log()
max()
min()
pow()
random()
round()
sin()
sqrt()
tan()
Instance Methods Getters
None.
Instance Methods Setters
None.

Statements

Operators