I need to calculate an angle of a triangle by using the tan^-1
function. On my calculator I can do this:
tan^-1(3/4)
// 3 and 4 are triangle side lengths
And it outputs 36 degrees. What is the alternative to this function in JavaScript? I tried Math.tan(3/4)
, Math.atan(3/4)
and all of the other tan functions I saw in the list, but none of them outputs the result in degrees I need (36).
Thank you.
In JavaScript, Math is a built-in object that contains different methods and properties used to perform mathematical operations. It contains an atan() function, which is used to compute a specified number's arc tangent. This is also known as the inverse tangent of a number.
Inverse Tan Formula In a right-angled triangle, the tangent of an angle (θ) is the ratio of its opposite side to the adjacent side. i.e., tan θ = (opposite side) / (adjacent side). Then by the definition of inverse tan, the inverse tan formula is, θ = tan-1[ (opposite side) / (adjacent side) ] .
atan2() function returns the angle in the plane (in radians) between the positive x-axis and the ray from (0, 0) to the point (x, y), for Math.
There is no build in function for that, since 1 radian = 180/pi degrees
you can do the following using Math.atan()
and Math.PI
var degree = Math.atan(3 / 4) * (180 / Math.PI);
document.write(degree);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With