What is the method for converting radians to degrees?

后端 未结 12 2658
慢半拍i
慢半拍i 2020-12-02 05:24

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 expre

相关标签:
12条回答
  • 2020-12-02 06:01

    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;
            }
    
    0 讨论(0)
  • 2020-12-02 06:02

    This works well enough for me :)

    // deg2rad * degrees = radians
    #define deg2rad (3.14159265/180.0)
    // rad2deg * radians = degrees
    #define rad2deg (180/3.14159265)
    
    0 讨论(0)
  • 2020-12-02 06:03

    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.

    0 讨论(0)
  • 2020-12-02 06:04

    180 degrees = PI * radians

    0 讨论(0)
  • 2020-12-02 06:05
    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

    0 讨论(0)
  • 2020-12-02 06:07

    In javascript you can do it this way

    radians = degrees * (Math.PI/180);
    
    degrees = radians * (180/Math.PI);
    
    0 讨论(0)
提交回复
热议问题