JavaScript atan() and atan2() Methods
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 »
|
JavaScript Math Object

Need an easy way to get data into XML, or transform XML to another format?
MapForce lets you map XML data to/from any combination of XML, database, flat file, Excel 2007, XBRL, or Web services data.
Then it transforms data instantly or auto-generates royalty-free data integration code for recurrent conversions.
Download a free, fully functional 30-day trial to experience the following features:
- Easy-to-use, graphical data mapping interface
- Instant data transformation
- XSLT 1.0/2.0 and XQuery code generation
- Java, C#, and C++ code generation
- Advanced data processing functions
- Support for all major relational databases including SQL Server, IBM DB2, Oracle, and more
- Visual Studio & Eclipse integration
Download a fully-functional trial today!
|
|
|
|