Javascript Sinus not correct

I am working with a friend on a small port from the bukkit WorldEdit plugin to minecraft pocket edition. The scripts are in JavaScript (so forget jQuery).

I tested my theoretical calculations to see if I can calculate the height c (hc) if I know the length a and the beta angle.

Triangle

Sample data: a: 20 cm beta: 40 °

Formula for calculating hc:

sin(40)*20

      

Result:

12.85575219374

      

I tested the formula in Chrome and IE and I got

14.902263209586957

      

Am I doing something wrong or am I having problems with my calculator / PC?

Hello

Miny

+3


source to share


1 answer


There are various ways to represent angles (degrees or radians). You are using degrees in your calculation, but the function sin

expects radians. Therefore, you need to convert degrees to radians.



function degToRad(deg) {
   return deg * Math.PI / 180;
}

      

+2


source







All Articles