1

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"

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
CoreCode
  • 2,227
  • 4
  • 22
  • 24

2 Answers2

4

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);
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
1

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.

Community
  • 1
  • 1
hawkfalcon
  • 652
  • 1
  • 12
  • 24
  • Yeah I just found that answer on http://geography.about.com/library/howto/htdegrees.htm.. Good answer though :) – CoreCode Apr 28 '12 at 05:41