Radian and Degree conversion in javascript

Seems as thought javascript doesnt come shipped with functions to convert radians to degrees and degrees to radians. Here’s a quick snippet to save you the headache of searching the net for the code


Math.degrees = function(rad)
 {
 return rad*(180/Math.PI);
 }

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

Use it like any other function in javacsript’s Math object:

var angle_in_deg = Math.degrees(3.14);
var angle_in_rad = Math.radians(180);

enjoy 😀

Advertisements

4 responses to “Radian and Degree conversion in javascript

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s