Two very simple operations that you may have to deal with if writing a JavaScript that deals with trigonometry are Math.degrees() and Math.radians(). These function can be easily defined as follows:
// Converts from degrees to radians.
Math.radians = function(degrees) {
return degrees * Math.PI / 180;
};
// Converts from radians to degrees.
Math.degrees = function(radians) {
return radians * 180 / Math.PI;
};
The name of these functions indicates the end result. Using the above definitions, you could run code such as the following to get the results indicated in the comments:
alert(Math.radians(90)); // 1.5707963267948966 alert(Math.radians(180)); // 3.141592653589793 alert(Math.degrees(1.5707963267948966)); // 90 alert(Math.degrees(3.141592653589793)); // 180
Personally, I don’t have any use for this at the moment, but if you do, feel free to take it and use it in your code. I figured if it is available in a language like Python, it might as well be available in the best scripting language, JavaScript!!!