Convert radians to degrees, minutes, and seconds

后端 未结 2 1065
没有蜡笔的小新
没有蜡笔的小新 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.

提交回复
热议问题