问题
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 ' seconds ".
e.g. 1.5 would be 1°30'0"
回答1:
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);
回答2:
Not sure how to do this with one command like >dms on the ti84, but you can use logic.
- The whole units of degrees will remain the same (i.e. in 121.135°
longitude, start with 121°). Multiply the decimal by 60 (i.e. .135 * 60 = 8.1).
The whole number becomes the minutes (8').
Take the remaining decimal and multiply by 60. (i.e. .1 * 60 = 6).
- The resulting number becomes the seconds (6"). Seconds can remain as a decimal.
- 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.
来源:https://stackoverflow.com/questions/10360534/convert-radians-to-degrees-minutes-and-seconds