Javascript (pure) - Find exact angle of triangle according to the table of trigonometric ratios

2

I would like to know if there is a way to find the exact angle of a triangle without depending on the table.

In my program, I'm getting the value in radian and turning it into degrees, but the value does not match that of the table.

My triangle is 233.5px in height and 180 in width. When I perform the sine, I find an angle of 45, but the table would be 52. And the angle I need to find is that of the table. The reason for the question is that I should get to these values through the program because I can not define them.

    
asked by anonymous 15.12.2017 / 18:16

1 answer

2

You can use the atan2 function to do this. Test below:

console.log(Math.atan2(233.5, 180) * 180 / Math.PI);

The output on the console is "52.37216305431494". As you may know, * 180 / Math.PI is to convert the radians response to degrees.

Note that the parameters of atan2 are y first and then x . In your case, y is the height of the triangle (233.5) and x is the width (180).

To understand how the atan2 function works, see that other question I answered .

    
15.12.2017 / 18:24