简体   繁体   中英

manual input for (ddd mm.m) convert to radians or decimal degrees? In python

I am writing a Python program for astronomical navigation using sextant observations as manual input. I use an angular form (ddd mm.m) or degrees, minutes and decimal minutes. I'm using the math library for further computations in my code. What would you suggest I do when the Lat/Lon are implemented in the program convert, them to radians or would decimal degrees be fine?.

My test position DR: 27°40.0'N; 102°22.5'W

    # DR: Dead Reckoning
latDR1 = input(float('div latidude degrees as (dd)')) #27
latDR2 = input(float('div latitude minutes as (mm.m)'))#40.0
latDR3 = input('div latitude hemisphere N/S')#N
latDR = float(latDR1+(latDR2/60))
if latDR3 == S: -(latDR);
    else: # here the error shows: 
else:
    ^
IndentationError: unexpected indent       

latDR

lonDR1 = input(float('div longditude degrees as (ddd)'))#102
lonDR2 = input(float('div longditude minutes as (mm.m)'))#22.5
lonDR3 = input('div longditude hemisphere E/W')#W
lonDR = float(latDR1+(latDR2/60))
if latDR3 == W: -(latDR);
    else: 
        latDR

DR = (latDR, lonDR)

It depends on what you are wanting to do with the values of latitude and longitude later. Normally they are needed for trigonometric functions ( sin , cos , tan etc) which will need the arguments to be in radians. This is easy to do with math.radians() and the result after calculation can be converted back for display with math.degrees() .

A word of advice: when reading sexagesimal values in parts as you are, you will want to combine the degrees, minutes and seconds (or decimal minutes) to decimal degrees first, then apply negation or a -1 multiplier for your sign convention (North & East +ve in your case; other choices are available for longitude...) if applicable. For example if you had 27deg 45.0' S, you want -1 * (27.0 + (45.0/60.0)) = -27.75 not -27.0 + (45.0/60.0) = -26.25

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM