# Using numpy for various math operations import numpy as np # allows numpy functions to be accessed with the # shortcut name np # Compute the traversal length of a line of latitude in kilometers # Note: numpy trig functions expect their inputs (arguments) # to be in radian measure (not degrees) r = 6378206.4 # Clarke 1866 estimate of earth radius in meters circumferenceEq = 2 * np.pi * r # circumference of earth along equator myLat = 45 # user's latitude (change to whatever you like) phi = np.radians(myLat) # convert a latitude in degrees to radians # and store as phi. This is necessary because # np.cos() assumes its argument is in radians. traversalAtPhiM = circumferenceEq * np.cos(phi) traversalAtPhiKM = traversalAtPhiM / 1000.0 print 'For a latitude of ' + str(myLat) + ' degrees, the traversal is ' \ + str(traversalAtPhiKM) + ' km' # Starting with an angle in degrees, find its sine. # Then take the inverse sine (arcsine) of the sine # to get back to the original angle. How close do you # get? We'll use radians all the way through so that # we don't get more chances for rounding error. myAngle = np.pi / 3.0 # pi / 3.0 is the radian equivalent of 60 degrees sinMyAngle = np.sin(myAngle) arcsinSinMyAngle = np.arcsin(sinMyAngle) print 'For the angle ' + str(myAngle) + '(in radians), its sin is ' \ + str(sinMyAngle) + ' and the arcsin of the sin is ' \ + str(arcsinSinMyAngle) + ' which has a difference of ' \ + str(myAngle - arcsinSinMyAngle) + ' from the original angle ' \ + '(which is ' + str(np.degrees(myAngle)) + ' in degrees)'