Advertisement
bolverk

flatness of middle earth

Apr 9th, 2015
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.89 KB | None | 0 0
  1. """
  2. In S. Weinberg's book "Gravitation and Cosmology", page 7 there's an exercise where the curvature of Middle earth is estimated by the distances between every pair of 4 points: Umbar, Hobbiton, Erebor and Dagorlad (which we denote as points A,B,C & D). There are overall 6 distinct pairs of points. Euclidean geometry together with the distances of 5 pairs can be used to estimate the 6th. The relative difference between the estimated distance and the actual distance should be the same order of magnitude as the ratio between the actual distance and the radius of curvature. If the estimated distance is greater than the actual distance, then the curvature is positive, otherwise it's negative.
  3. """
  4.  
  5. def cosine_angle(os, ns1, ns2):
  6.     """
  7.    Returns the cosine of the angle in a triangle, accoring to the cosine theorem
  8.    os - Length of opposing side
  9.    ns1 - Length of neighboring side
  10.    ns2 - Length of the other neighboring side
  11.  
  12.    >>> abs(cosine_angle(2.**0.5,1.,1.))<1e-14
  13.    True
  14.    >>> import math; abs(cosine_angle(1.,1.,1.)-math.cos(math.pi/3))<1e-14
  15.    True
  16.    """
  17.    
  18.     return (ns1**2+ns2**2-os**2)/(2*ns1*ns2)
  19.  
  20. def main():
  21.  
  22.     import math
  23.  
  24.     # Distances between points, in miles
  25.     AB = 1112
  26.     AC = 1498
  27.     AD = 780
  28.     BC = 813
  29.     BD = 960
  30.     CD = 735
  31.  
  32.     cos_ADB = cosine_angle(AB,AD,BD)
  33.     cos_BDC = cosine_angle(BC,BD,CD)
  34.     sin_ADB = math.sqrt(1-cos_ADB**2)
  35.     sin_BDC = math.sqrt(1-cos_BDC**2)
  36.     cos_ADC = cos_ADB*cos_BDC-sin_ADB*sin_BDC
  37.     estimated_AC = math.sqrt(AD**2 + CD**2 - 2*AD*CD*cos_ADC)
  38.  
  39.     print('Estimated length of AC[miles]: '+str(estimated_AC))
  40.     print('Actual length of AC[miles]: '+str(AC))
  41.     print('Difference between them [miles]: '+str(AC-estimated_AC))
  42.     print('Relative difference: '+str(100*(AC-estimated_AC)/AC)[:5]+'%')
  43.  
  44. if __name__ == '__main__':
  45.     import doctest
  46.     doctest.testmod()
  47.  
  48.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement