JavaScript Math Object
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 arctangent of the quotient of its arguments. The angle returned is a numeric value between PI and -PI and represents the counterclockwise angle in radians (not degrees) between the positive X axis and the point (x, y).
Note: With atan2(), the y coordinate is passed as the first argument and the x coordinate is passed as the second argument!
| Parameter | Description |
|---|---|
| x | Required. A number |
| y | Required. A number |
![]()
The atan() and atan2() methods are supported in all major browsers.
Assume you had a point with the (x,y) coordinates of (4,8), you could calculate the angle in radians between that point and the positive X axis as follows:
The output of the code above will be:
We can also calculate the arctangent of the ratio of the two coordinates above (8/4 = 2), which will produce the same output:
The output of the code above will be:
JavaScript Math Object
| WEB HOSTING |
|---|
| Best Web Hosting |
| PHP MySQL Hosting |
| Best Hosting Coupons |
| UK Reseller Hosting |
| Cloud Hosting |
| Top Web Hosting |
| $7.95/mo SEO Hosting |
| Premium Website Design |
| WEB BUILDING |
|---|
| XML Editor - Free Trial! |
| FREE Website BUILDER |
| Free Website Templates Free CSS Templates |
| Make Your Own Website |
| W3SCHOOLS EXAMS |
|---|
|
Get Certified in: HTML, CSS, JavaScript, XML, PHP, and ASP |
| W3SCHOOLS BOOKS |
|---|
|
New Books: HTML, CSS JavaScript, and Ajax |
| STATISTICS |
|---|
|
Browser Statistics Browser OS Browser Display |
| SHARE THIS PAGE |
|---|