Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  53] [ 4]  / answers: 1 / hits: 154409  / 12 Years ago, wed, march 14, 2012, 12:00:00

When I'm working with math in JS I would like its trig functions to use degree values instead of radian values. How would I do that?


More From » math

 Answers
223

You can use a function like this to do the conversion:



function toDegrees (angle) {
return angle * (180 / Math.PI);
}


Note that functions like sin, cos, and so on do not return angles, they take angles as input. It seems to me that it would be more useful to you to have a function that converts a degree input to radians, like this:



function toRadians (angle) {
return angle * (Math.PI / 180);
}


which you could use to do something like tan(toRadians(45)).


[#86847] Tuesday, March 13, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elishaannac

Total Points: 28
Total Questions: 97
Total Answers: 101

Location: Samoa
Member since Mon, Nov 8, 2021
3 Years ago
;