Hans Sjunnesson
Hans Sjunnesson

Reputation: 22329

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?

Upvotes: 181

Views: 149164

Answers (12)

n0099
n0099

Reputation: 1393

.NET8: https://github.com/dotnet/runtime/issues/86402

double.RadiansToDegrees(1);
float.DegreesToRadians(1);

Upvotes: 4

Netsi1964
Netsi1964

Reputation: 3620

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));

Upvotes: -1

Rayiez
Rayiez

Reputation: 1599

In javascript you can do it this way

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

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

Upvotes: 7

Dave Costa
Dave Costa

Reputation: 48131

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

Upvotes: 312

Axeman
Axeman

Reputation: 357

radians = (degrees/360) * 2 * pi

Upvotes: -2

Warpling
Warpling

Reputation: 2115

This works well enough for me :)

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

Upvotes: 0

thesmallprint
thesmallprint

Reputation: 2391

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.

Upvotes: 9

manobes
manobes

Reputation: 31

pi Radians = 180 degrees

So 1 degree = pi/180 radians

or 1 radian = 180/pi degrees

Upvotes: -1

nsayer
nsayer

Reputation: 17047

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.

Upvotes: 11

Hannes Ovrén
Hannes Ovrén

Reputation: 21851

360 degrees = 2*pi radians

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

Upvotes: -1

kokos
kokos

Reputation: 43644

360 degrees is 2*PI radians

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

Upvotes: -1

Charles Graham
Charles Graham

Reputation: 24835

180 degrees = PI * radians

Upvotes: -1

Related Questions