[algorithm] What is the method for converting radians to degrees?

I run into this occasionally and always forget how to do it.

One of those things that pop up ever so often.

Also, what's the formula to convert angles expressed in radians to degrees and back again?

This question is related to algorithm math trigonometry

The answer is


For double in c# this might be helpful:

        public static double Conv_DegreesToRadians(this double degrees)
        {
            //return degrees * (Math.PI / 180d);
            return degrees * 0.017453292519943295d;
        }
        public static double Conv_RadiansToDegrees(this double radians)
        {
            //return radians * (180d / Math.PI);
            return radians * 57.295779513082323d;
        }

Here is some code which extends Object with rad(deg), deg(rad) and also two more useful functions: getAngle(point1,point2) and getDistance(point1,point2) where a point needs to have a x and y property.

Object.prototype.rad = (deg) => Math.PI/180 * deg;
Object.prototype.deg = (rad) => 180/Math.PI * rad;
Object.prototype.getAngle = (point1, point2) => Math.atan2(point1.y - point2.y, point1.x - point2.x);
Object.prototype.getDistance = (point1, point2) => Math.sqrt(Math.pow(point1.x-point2.x, 2) + Math.pow(point1.y-point2.y, 2));

360 degrees is 2*PI radians

You can find the conversion formulas at: http://en.wikipedia.org/wiki/Radian#Conversion_between_radians_and_degrees.


360 degrees = 2*pi radians

That means deg2rad(x) = x*pi/180 and rad2deg(x) = 180x/pi;


x rads in degrees - > x*180/pi
x degrees in rads -> x*pi/180

I guess if you wanted to make a function for this [in PHP]:

function convert($type, $num) {
    if ($type == "rads") {
          $result = $num*180/pi();
        }

    if ($type == "degs") {
          $result = $num*pi()/180;
        }

    return $result;
  }

Yes, that could probably be written better.


180 degrees = PI * radians


pi Radians = 180 degrees

So 1 degree = pi/180 radians

or 1 radian = 180/pi degrees


In javascript you can do it this way

radians = degrees * (Math.PI/180);

degrees = radians * (180/Math.PI);

This works well enough for me :)

// deg2rad * degrees = radians
#define deg2rad (3.14159265/180.0)
// rad2deg * radians = degrees
#define rad2deg (180/3.14159265)

a complete circle in radians is 2*pi. A complete circle in degrees is 360. To go from degrees to radians, it's (d/360) * 2*pi, or d*pi/180.


radians = (degrees/360) * 2 * pi

Examples related to algorithm

How can I tell if an algorithm is efficient? Find the smallest positive integer that does not occur in a given sequence Efficiently getting all divisors of a given number Peak signal detection in realtime timeseries data What is the optimal algorithm for the game 2048? How can I sort a std::map first by value, then by key? Finding square root without using sqrt function? Fastest way to flatten / un-flatten nested JSON objects Mergesort with Python Find common substring between two strings

Examples related to math

How to do perspective fixing? How to pad a string with leading zeros in Python 3 How can I use "e" (Euler's number) and power operation in python 2.7 numpy max vs amax vs maximum Efficiently getting all divisors of a given number Using atan2 to find angle between two vectors How to calculate percentage when old value is ZERO Finding square root without using sqrt function? Exponentiation in Python - should I prefer ** operator instead of math.pow and math.sqrt? How do I get the total number of unique pairs of a set in the database?

Examples related to trigonometry

How to calculate the angle between a line and the horizontal axis? Calculating the position of points in a circle 2D Euclidean vector rotations How does C compute sin() and other math functions? How to use the PI constant in C++ How do I calculate a point on a circle’s circumference? What is the method for converting radians to degrees?