How to calculate the angle of a right triangle using the Javascript Math library?

Consider the following triangle:

enter image description here

I want to calculate the angle X

I have the following:

    var opposite = 2.5;
    var hypotenuse = 5;

    var sinOfAngleX = opposite / hypotenuse; // 0.5

So now I know what Math.sin(valueofAngleX)will return 0.5.

But how do I get the angle value if I know the sine of the angle using the Math () library?

According to this tutorial , I need to do:

var angleX = sin to the power of negative one of 0.5

but I don’t know how to translate this to JS.

I tried:

var angleX = Math.pow(Math.sin(sinOfAngleX), -1);

but it returns 2.085829642933488 , which is obviously incorrect. The correct answer should be 30

And in case all of the above is wrong for a start, does anyone know how I can correctly calculate the angle X using the JS Math () library?

Thank!

+4
2

:

Math.asin(sinOfAngleX) * 180/Math.PI

sinOfAngleX = 0.5, Math.asin(sinOfAngleX) 0.5235987755982989. . , 180/Math.PI, 30º

+13

ES6 Math Object

 Math.hypot(3, 4)

enter image description here

+1

Source: https://habr.com/ru/post/1570030/


All Articles