Convert radians to degrees, minutes, and seconds

后端 未结 2 1066
没有蜡笔的小新
没有蜡笔的小新 2021-01-07 10:20

I am looking on a way to convert decimals to degrees in C. For instance, the asin() function in C returns a decimal number but I need that number to be in degrees ° minutes

相关标签:
2条回答
  • 2021-01-07 10:55

    Not sure how to do this with one command like >dms on the ti84, but you can use logic.

    1. The whole units of degrees will remain the same (i.e. in 121.135°
      longitude, start with 121°).
    2. Multiply the decimal by 60 (i.e. .135 * 60 = 8.1).

    3. The whole number becomes the minutes (8').

    4. Take the remaining decimal and multiply by 60. (i.e. .1 * 60 = 6).

    5. The resulting number becomes the seconds (6"). Seconds can remain as a decimal.
    6. Take your three sets of numbers and put them together, using the symbols for degrees (°), minutes (‘), and seconds (") (i.e. 121°8'6" longitude) Source: http://geography.about.com/library/howto/htdegrees.htm

    A little bit of searching and i found this in c#: Converting from Decimal degrees to Degrees Minutes Seconds tenths.

    double decimal_degrees; 
    
    // set decimal_degrees value here
    
    double minutes = (decimal_degrees - Math.Floor(decimal_degrees)) * 60.0; 
    double seconds = (minutes - Math.Floor(minutes)) * 60.0;
    double tenths = (seconds - Math.Floor(seconds)) * 10.0;
    // get rid of fractional part
    minutes = Math.Floor(minutes);
    seconds = Math.Floor(seconds);
    tenths = Math.Floor(tenths);
    

    But as he said, it will need to be convered from radians to degrees first.

    0 讨论(0)
  • 2021-01-07 10:56

    The asin function returns radians. There are 2 π radians in a circle.

    There are 360 degrees in a circle, 60 minutes in a degree, and 60 seconds in a minute. So there are 360*60*60 seconds in a circle.

    double radians = asin(opposite / hypotenuse);
    int totalSeconds = (int)round(radians * 360 * 60 * 60 / (2 * M_PI));
    int seconds = totalSeconds % 60;
    int minutes = (totalSeconds / 60) % 60;
    int degrees = totalSeconds / (60 * 60);
    
    0 讨论(0)
提交回复
热议问题