How to use atan2 in JavaScript

In this article, I will explain use of atan2() method in JavaScript.
  • 2558

JavaScript atan2() Method

  • atan() method of math object returns the arctangent of the quotient of its arguments.

  • atan() method returns a numeric value between -pi/2 and pi/2 radians representing the angle theta of an (x,y) point.

  • In atan2(),the x coordinate is passed as the second argument and, the y coordinate is passed as the first argument.

Syntax

Math.atan2(x,y)

  • x and y is a Required number

Example

In the following example show to how atan2() method with (12,6) coordinate can be used.

<!DOCTYPE html>

<html>

<body>

<h3 style="background-color:Silver">atan2() Method Example</h3>

<p id="demo">Click the button to display the arctangent of 12/6</p>

<button onclick="myFunction()">Click</button>

<script type="text/javascript">

    function myFunction() {

        document.getElementById("demo").innerHTML = Math.atan2(12, 6);

    }

</script>

</body>

</html>

Output1

atan2 output.jpg

Output2

atan2 final.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.