Advertisement
FaceDeer

AsterRingMaker.py

Mar 15th, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.09 KB | None | 0 0
  1. import random
  2. from datetime import datetime
  3.  
  4. # AsteroidsRingMaker
  5. # by JackDole
  6. # 2016.03.15 16:36:56
  7. # converted to Python and enhanced by FaceDeer
  8.  
  9. #daysYear = 365.24218985
  10. #AU = 149597870.691
  11. #eMass = 5.9736e24
  12.  
  13. #uncomment this line if you want repeatable results
  14. #random.seed(100)
  15.  
  16. # Amount of asteroids
  17. NumberOfAster=200
  18. # Name of the asteroids - a serial number is appended
  19. AsterName='Vulkanoid'
  20.  
  21. RingCenter='Sol'
  22.  
  23. # Orbital radii in AU
  24. InnerRadius=0.15
  25. OuterRadius=0.18
  26.  
  27. # Radius of asteroids in KM
  28. MaxRadiusOfAster=3
  29. MinRadiusOfAster=0.1
  30.  
  31. #orbital eccentricity
  32. MaxEccentricity=0.001
  33. MinEccentricity=0
  34.  
  35. # Orbital inclination +- in degrees
  36. MaxInclination=10
  37.  
  38. #Probability that the asteroid won't be given a rotation rate, leaving it tide-locked
  39. ChanceOfTideLock = 0.1
  40. #rotation periods in hours. See https://www.boulder.swri.edu/~bottke/rubble/node3.html
  41. MaxRotationPeriod = 12
  42. MinRotationPeriod = 0.1
  43.  
  44. RefPlane='Ecliptic'
  45. epoch=2457395.5
  46. FileName= '{0}_{1}.sc'.format(AsterName, NumberOfAster)
  47.  
  48. template ="""
  49. Asteroid "{AsterName} {count}"
  50. {{
  51. \tParentBody\t"{RingCenter}"
  52. \tClass\t\t"Asteroid"
  53. \tRadius\t\t{radius}
  54. {rotation}
  55. \tOrbit
  56. \t{{
  57. \t\tEpoch\t\t\t{epoch}
  58. \t\tSemiMajorAxis\t{semi}
  59. \t\tEccentricity\t{eccen}
  60. \t\tInclination\t\t{incl}
  61. \t\tAscendingNode\t{ascen}
  62. \t\tArgOfPericen\t{argof}
  63. \t\tMeanAnomaly\t\t0.0
  64. \t\tRefPlane\t\t"{RefPlane}"
  65. \t}}
  66. }}
  67.  
  68. """
  69.  
  70. #three different random number generators that give a floating point number between
  71. #the two parameters but with different distributions
  72.  
  73. def uniform(a, b):
  74.     return random.uniform(a, b)
  75.  
  76. def triangular(a, b):
  77.     return random.triangular(a, b, (a+b)/2.0)
  78.  
  79. # A normal distribution placing a and b at three standard deviations out from the mean
  80. # clamping the result so that there are no outliers beyond the desired range
  81. def gaussian(a, b):
  82.     result = random.gauss((a+b)/2.0, (b-a)/6.0)
  83.     return max(min(result, b), a)
  84.  
  85. randomGenerator = gaussian
  86.  
  87. parameters = {'AsterName' : AsterName, 'RingCenter' : RingCenter, 'RefPlane' : RefPlane, 'epoch' : epoch}
  88.  
  89. with open(FileName, 'w') as outputfile:
  90.     outputfile.write('// Asteroids made with AsteroidsRingMaker\n// {0}\n\n'.format(datetime.today()))
  91.  
  92.     for count in range(NumberOfAster):
  93.  
  94.         parameters['count'] = count
  95.         parameters['semi'] = randomGenerator(InnerRadius, OuterRadius)
  96.         parameters['radius'] = randomGenerator(MinRadiusOfAster, MaxRadiusOfAster)
  97.         parameters['incl'] = randomGenerator(-MaxInclination, MaxInclination)
  98.         parameters['eccen'] = randomGenerator(MinEccentricity, MaxEccentricity)
  99.         parameters['argof'] = random.uniform(0,360)
  100.         parameters['ascen'] = random.uniform(0,360)
  101.  
  102.         if random.random() > ChanceOfTideLock:
  103.             rotation = randomGenerator(MinRotationPeriod,MaxRotationPeriod)
  104.             obliquity = random.uniform(0,360)
  105.             parameters['rotation'] = '\tRotationPeriod\t{0}\n\tObliquity\t\t{1}\n'.format(rotation, obliquity)
  106.         else:
  107.             parameters['rotation'] = ''
  108.  
  109.         outputfile.write(template.format(**parameters))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement