What is the method for converting radians to degrees?

128,634

Solution 1

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

Solution 2

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.

Solution 3

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.

Solution 4

In javascript you can do it this way

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

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

Solution 5

This works well enough for me :)

// deg2rad * degrees = radians
#define deg2rad (3.14159265/180.0)
// rad2deg * radians = degrees
#define rad2deg (180/3.14159265)
Share:
128,634

Related videos on Youtube

Hans Sjunnesson
Author by

Hans Sjunnesson

I'm the Head of Code at Fatshark. We're a nice little video game studio, in Stockholm, Sweden - most recently famous for Warhammer: Vermintide 2.

Updated on June 08, 2020

Comments

  • Hans Sjunnesson
    Hans Sjunnesson almost 4 years

    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?

    • Tanky Woo
      Tanky Woo over 15 years
      I don't see why people are downvoting this; some people aren't mathematically inclined.
    • DevelopingChris
      DevelopingChris over 15 years
      its just a matter of phrasing. I rephrased it as a programming problem instead of a math problem, and voila, it fits.
    • Hans Sjunnesson
      Hans Sjunnesson over 15 years
      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.
    • Michael J. Barber
      Michael J. Barber over 12 years
      The title of this question makes no sense. "[B]uilt in method" --- built in to what?
    • Hans Sjunnesson
      Hans Sjunnesson over 12 years
      Heck if I know, someone edited it.
    • Alex
      Alex over 11 years
      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
      Alex over 11 years
      i am going to go ask for a method for converting Celsius to Fahrenheit and back, i keep forgetting that one too
    • Ben
      Ben over 11 years
      @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...
    • Alex
      Alex over 11 years
      @Ben, i did not notice the date, but in case you did not recognize it, it was sarcasm.
    • Hans Sjunnesson
      Hans Sjunnesson over 11 years
      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.
  • Axel Kemper
    Axel Kemper over 11 years
    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
  • garg
    garg over 10 years
    180 degrees = pi radians.
  • Bart
    Bart about 10 years
    Maybe this wasn't available in 2008, but nowadays you can just use the Math.PI constant.
  • Hogun
    Hogun about 10 years
    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?
  • Dave Costa
    Dave Costa about 10 years
    @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".
  • Pawel
    Pawel over 7 years
    No need for parens degrees = radians * 180 / Math.PI; radians = degrees * Math.PI / 180;
  • Jacksonkr
    Jacksonkr about 7 years
    @Pawel While you are correct, I dare say the author used the parens to convey a concept about how the function comes together conceptually.