Compute Arctangent of y/x
Computes the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value.
Examples
Filter
function calcAngleDegrees(x, y) {
return Math.atan2(y, x) * 180 / Math.PI;
}
console.log(calcAngleDegrees(5, 5));
//expected output: 45
console.log(calcAngleDegrees(10, 10));
//expected output: 45
console.log(calcAngleDegrees(0, 10));
//expected output: 90
Math.atan2(90, 15); // 1.4056476493802699
Math.atan2(15, 90); // 0.16514867741462683
Math.atan2(±0, -0); // ±PI.
Math.atan2(±0, +0); // ±0.
Math.atan2(±0, -x); // ±PI for x > 0.
Math.atan2(±0, x); // ±0 for x > 0.
Math.atan2(-y, ±0); // -PI/2 for y > 0.
Math.atan2(y, ±0); // PI/2 for y > 0.
Math.atan2(±y, -Infinity); // ±PI for finite y > 0.
Math.atan2(±y, +Infinity); // ±0 for finite y > 0.
Math.atan2(±Infinity, x); // ±PI/2 for finite x.
Math.atan2(±Infinity, -Infinity); // ±3*PI/4.
Math.atan2(±Infinity, +Infinity); // ±PI/4.
package main
import (
"fmt"
"math"
)
/*
Special Cases:
Atan2(y, NaN) = NaN
Atan2(NaN, x) = NaN
Atan2(+0, x>=0) = +0
Atan2(-0, x>=0) = -0
Atan2(+0, x<=-0) = +Pi
Atan2(-0, x<=-0) = -Pi
Atan2(y>0, 0) = +Pi/2
Atan2(y<0, 0) = -Pi/2
Atan2(+Inf, +Inf) = +Pi/4
Atan2(-Inf, +Inf) = -Pi/4
Atan2(+Inf, -Inf) = 3Pi/4
Atan2(-Inf, -Inf) = -3Pi/4
Atan2(y, +Inf) = 0
Atan2(y>0, -Inf) = +Pi
Atan2(y<0, -Inf) = -Pi
Atan2(+Inf, x) = +Pi/2
Atan2(-Inf, x) = -Pi/2
*/
func main() {
fmt.Printf("%.2f", math.Atan2(0, 0))
}
Last Run
:
0.00