176

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?

grahamparks
  • 16,130
  • 5
  • 49
  • 43
Hans Sjunnesson
  • 21,745
  • 17
  • 54
  • 63
  • 6
    I don't see why people are downvoting this; some people aren't mathematically inclined. – thesmallprint Sep 25 '08 at 20:53
  • 1
    its just a matter of phrasing. I rephrased it as a programming problem instead of a math problem, and voila, it fits. – DevelopingChris Sep 25 '08 at 20:56
  • Excellent, I truly believe these kinds of basic questions have a place on stack overflow if it is to be the programming information portal of reckon. – Hans Sjunnesson Sep 25 '08 at 21:23
  • 4
    The title of this question makes no sense. "[B]uilt in method" --- built in to what? – Michael J. Barber Sep 27 '11 at 15:19
  • Heck if I know, someone edited it. – Hans Sjunnesson Sep 27 '11 at 16:05
  • so, for a 2 second google search you would get 31+ points and for a one-line answer someone will get 100+ points? sigh... – Alex Jan 07 '13 at 22:39
  • 1
    i am going to go ask for a method for converting Celsius to Fahrenheit and back, i keep forgetting that one too – Alex Jan 07 '13 at 22:40
  • @alex, you do that now you'll be trashed; this is a _very_ old question and the site has moved on. Flag it as off-topic and don't let it bother you... – Ben Jan 07 '13 at 23:02
  • @Ben, i did not notice the date, but in case you did not recognize it, it was sarcasm. – Alex Jan 08 '13 at 15:21
  • 10
    StackOverflow is more than a forum for questions and answers. It's a place of reference. I originally put the question here as a reference question, because it's really really common. It belongs here so when someone answers "Just Google it", Google will direct you here. – Hans Sjunnesson Jan 09 '13 at 15:20

12 Answers12

302
radians = degrees * (pi/180)

degrees = radians * (180/pi)

As for implementation, the main question is how precise you want to be about the value of pi. There is some related discussion here

Community
  • 1
  • 1
Dave Costa
  • 47,262
  • 8
  • 56
  • 72
  • 13
    Pi = 4 * ArcTan(1) could be used, in case you don't have Pi on you system/calculator or just don't want to type it in with all decimals – Axel Kemper Jan 07 '13 at 23:46
  • 27
    Maybe this wasn't available in 2008, but nowadays you can just use the `Math.PI` constant. – Bart Feb 24 '14 at 14:19
  • is this correct?? PI radians = 180 degrees radians = 180 degrees / PI radians = 180/PI * degrees i don't known your formula. why are 180 and PI changed? – Hogun Mar 14 '14 at 06:00
  • 1
    @Hogun Unit labels are not the same thing as algebraic variables. When you say "PI radians = 180 degrees" you are speaking in units, equivalent to saying "1 foot = 12 inches". You don't then take the unit labels and treat them as variables, which would give you the obviously wrong equation "feet = 12*inches". – Dave Costa Mar 15 '14 at 20:19
  • 1
    No need for parens degrees = radians * 180 / Math.PI; radians = degrees * Math.PI / 180; – Pawel Aug 25 '16 at 13:12
  • 3
    @Pawel While you are correct, I dare say the author used the parens to convey a concept about how the function comes together conceptually. – Jacksonkr Mar 28 '17 at 16:02
11

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.

nsayer
  • 16,925
  • 3
  • 33
  • 51
10

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.

thesmallprint
  • 2,363
  • 3
  • 23
  • 31
6

In javascript you can do it this way

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

degrees = radians * (180/Math.PI);
Rayiez
  • 1,420
  • 19
  • 20
1

This works well enough for me :)

// deg2rad * degrees = radians
#define deg2rad (3.14159265/180.0)
// rad2deg * radians = degrees
#define rad2deg (180/3.14159265)
Warpling
  • 2,024
  • 2
  • 22
  • 38
0

180 degrees = PI * radians

Charles Graham
  • 24,293
  • 14
  • 43
  • 56
0

360 degrees is 2*PI radians

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

kokos
  • 43,096
  • 5
  • 36
  • 32
0

360 degrees = 2*pi radians

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

Hannes Ovrén
  • 21,229
  • 9
  • 65
  • 75
0

pi Radians = 180 degrees

So 1 degree = pi/180 radians

or 1 radian = 180/pi degrees

manobes
  • 33
  • 1
  • 1
  • 4
0

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;
        }
Koray
  • 1,768
  • 1
  • 27
  • 37
0

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));
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Netsi1964
  • 3,244
  • 1
  • 27
  • 17
-1
radians = (degrees/360) * 2 * pi
Chuck Norris
  • 15,207
  • 15
  • 92
  • 123
Axeman
  • 349
  • 1
  • 7