javascript Math.cos muestra una respuesta diferente en comparación con la calculadora científica

i created a program in javascript that computes vector coordinates, everything was smooth since i have the correct formula, but when i try to conpute for the cosine of 143.1301 using Math.cos in javascript it returns 0.1864 instead of 0.7999 from the scientific calculator why is that? can anyone explain to me why? and also please give me the solution for this problem... thanks in advance... :) here;s a sample of my code

function cyltoxec(a)  
{
    ans = Math.cos(a);  
    return ans.toFixed(4);
}
var = x;
return cyltoxec(x);

preguntado el 27 de agosto de 11 a las 15:08

Welcome to Stackoverflow. Please use {} present on the editor window to format your code. You can always have a preview of what it looks like down under the editor window even before posting. -

0.1864 is in radians, 0.8 is in degrees. -

2 Respuestas

Trigonometric functions in JavaScript (and indeed, in most mathematical parlance and programming) use radianes as the angular unit, not degrees.

Hay 2 * Pi radians in 360 Degrees. Thus, the cosine of a degrees is

Math.cos(a * Math.PI/180)

Respondido 27 ago 11, 19:08

oh thank you! thank you! you save me a lot of trouble there! :) - Philip

Math.cos expects its argument to be in radians, not degrees. Try Math.cos(a * Math.PI/180) en vez.

Respondido 27 ago 11, 19:08

you and Adam have the same answer, thank you for the help, im so glad i did not made i mistake asking in this forum, thank you so much! - Philip

You are welcome. Don't forget to click the checkmark beside Adam's answer to say that you accept it. - Alcance

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.