From http://www.w3schools.com (Copyright Refsnes Data)

JavaScript atan() and atan2() Methods


Math Object Reference JavaScript Math Object

Definition and Usage

The atan() method returns the arctangent of a number as a numeric value between -PI/2 and PI/2 radians.

The atan2() method returns the angle theta of an (x,y) point as a numeric value between -PI and PI radians.

Syntax

Math.atan(x)

Math.atan2(x,y)

Parameter Description
x Required. A number
y Required. A number


Examples

Example 1 - atan()

Return the arctangent of different numbers with the atan() method:

<script type="text/javascript">

document.write(Math.atan(0.50) + "<br />");
document.write(Math.atan(-0.50) + "<br />");
document.write(Math.atan(5) + "<br />");
document.write(Math.atan(10) + "<br />");
document.write(Math.atan(-5) + "<br />");
document.write(Math.atan(-10));

</script>

The output of the code above will be:

0.4636476090008061
-0.4636476090008061
1.373400766945016
1.4711276743037347
-1.373400766945016
-1.4711276743037347

Try it yourself »

Example 2 - atan2()

Return the angle theta of different (x,y) points with the atan2() method:

<script type="text/javascript">

document.write(Math.atan2(0.50,0.50) + "<br />");
document.write(Math.atan2(-0.50,-0.50) + "<br />");
document.write(Math.atan2(5,5) + "<br />");
document.write(Math.atan2(10,20) + "<br />");
document.write(Math.atan2(-5,-5) + "<br />");
document.write(Math.atan2(-10,10));

</script>

The output of the code above will be:

0.7853981633974483
-2.356194490192345
0.7853981633974483
0.4636476090008061
-2.356194490192345
-0.7853981633974483

Try it yourself »


Math Object Reference JavaScript Math Object

From http://www.w3schools.com (Copyright Refsnes Data)