Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from datetime import datetime
- # AsteroidsRingMaker
- # by JackDole
- # 2016.03.15 16:36:56
- # converted to Python and enhanced by FaceDeer
- daysYear = 365.24218985
- AU = 149597870.691
- #eMass = 5.9736e24
- #uncomment this line if you want repeatable results
- random.seed(100)
- # Amount of asteroids
- NumberOfAster=200
- # Name of the asteroids - a serial number is appended
- AsterName='Vulkanoid'
- RingCenter='Sol'
- # Orbital radii in AU
- InnerRadius=0.15
- OuterRadius=0.18
- # Radius of asteroids in KM
- MaxRadiusOfAster=3
- MinRadiusOfAster=0.1
- #orbital eccentricity
- MaxEccentricity=0.001
- MinEccentricity=0
- # Orbital inclination +- in degrees
- MaxInclination=10
- #rotation periods in hours. See https://www.boulder.swri.edu/~bottke/rubble/node3.html
- MaxRotationPeriod = 12
- MinRotationPeriod = 0.1
- ChanceOfMoon = 0.5
- ChanceOfBinary = 0.25
- FileName= '{0}_{1}.sc'.format(AsterName, NumberOfAster)
- class Orbit:
- def print(self):
- result = ['\tOrbit\n\t{']
- if hasattr(self, 'epoch'):
- result.append('\t\tEpoch\t\t\t{0}'.format(self.epoch))
- else:
- result.append('\t\tEpoch\t\t\t2457395.5')
- if hasattr(self, 'semi'):
- result.append('\t\tSemiMajorAxis\t{0}'.format(self.semi))
- if hasattr(self, 'period'):
- result.append('\t\tPeriod\t\t\t{0}'.format(self.period))
- if hasattr(self, 'eccen'):
- result.append('\t\tEccentricity\t{0}'.format(self.eccen))
- if hasattr(self, 'incl'):
- result.append('\t\tInclination\t\t{0}'.format(self.incl))
- if hasattr(self, 'ascen'):
- result.append('\t\tAscendingNode\t{0}'.format(self.ascen))
- if hasattr(self, 'argof'):
- result.append('\t\tArgOfPericen\t{0}'.format(self.argof))
- if hasattr(self, 'refplane'):
- result.append('\t\tRefPlane\t\t"{0}"'.format(self.refplane))
- else:
- result.append('\t\tRefPlane\t\t"Ecliptic"')
- result.append('\t\tMeanAnomaly\t\t0.0')
- result.append('\t}')
- return '\n'.join(result)
- class Asteroid:
- def print(self):
- result = ['Asteroid "{0}"\n{{\n\tParentBody\t"{1}"\n\tClass\t\t"Asteroid"'.format(self.name, self.parent)]
- if hasattr(self, 'radius'):
- result.append('\tRadius\t\t{0}'.format(self.radius))
- if hasattr(self, 'rotation'):
- result.append('\tRotationPeriod\t{0}'.format(self.rotation))
- if hasattr(self, 'obliquity'):
- result.append('\n\tObliquity\t\t{0}\n'.format(self.obliquity))
- result.append(self.orbit.print())
- result.append('}')
- return '\n'.join(result)
- def getSafeMoonRadius(self):
- return self.radius/AU * 1.2
- class BinaryAsteroid:
- def print(self):
- result = ['Barycenter "{0}"\n{{\n\tParentBody\t"{1}"'.format(self.name, self.parent)]
- result.append(orbit.print())
- result.append('}\n')
- asteroid = Asteroid()
- asteroid.name = self.name + " A"
- asteroid.parent = self.name
- asteroid.radius = self.radius1
- asteroid.orbit = self.componentorbit
- result.append(asteroid.print())
- asteroid.name = self.name + " B"
- asteroid.radius = self.radius2
- asteroid.orbit.argof = (asteroid.orbit.argof + 180) % 360
- result.append(asteroid.print())
- return '\n'.join(result)
- #three different random number generators that give a floating point number between
- #the two parameters but with different distributions
- def uniform(a, b):
- return random.uniform(a, b)
- # A normal distribution placing a and b at three standard deviations out from the mean
- # clamping the result so that there are no outliers beyond the desired range
- def gaussian(a, b):
- result = random.gauss((a+b)/2.0, (b-a)/6.0)
- return max(min(result, b), a)
- randomGenerator = gaussian
- def makeMoon(parentAsteroid, moonCount):
- innerLimit = parentAsteroid.radius/AU * 1.1
- outerLimit = innerLimit * 20
- moon = Asteroid()
- moon.radius = random.uniform(parentAsteroid.radius/20, parentAsteroid.radius/4)
- moon.name = parentAsteroid.name + '.{0}'.format(moonCount)
- moon.parent = parentAsteroid.name
- orbit = Orbit()
- orbit.parent = parentAsteroid.name
- orbit.refplane = 'Equator'
- orbit.semi = random.uniform(innerLimit, outerLimit)
- orbit.incl = randomGenerator(-90, 90)
- orbit.eccen = randomGenerator(0, 0.1)
- orbit.argof = random.uniform(0,360)
- orbit.ascen = random.uniform(0,360)
- moon.orbit = orbit
- return moon.print()
- def makeAsteroid(count, orbit):
- asteroid = Asteroid()
- asteroid.name = AsterName + ' {0}'.format(count)
- asteroid.parent = RingCenter
- asteroid.radius = randomGenerator(MinRadiusOfAster, MaxRadiusOfAster)
- asteroid.rotation = randomGenerator(MinRotationPeriod,MaxRotationPeriod)
- asteroid.obliquity = random.uniform(0,360)
- asteroid.orbit = orbit
- output = [asteroid.print()]
- moonCount = 0
- while random.random() > ChanceOfMoon and moonCount < 10:
- moonCount = moonCount + 1
- output.append(makeMoon(asteroid, moonCount))
- return '\n'.join(output)
- def makeBinaryAsteroid(count, orbit):
- binary = BinaryAsteroid()
- binary.name = AsterName + ' {0}'.format(count)
- binary.parent = RingCenter
- binary.radius1 = randomGenerator(MinRadiusOfAster, MaxRadiusOfAster)
- binary.radius2 = binary.radius1 * random.uniform(0.25,1)
- binary.orbit = orbit
- componentOrbit = Orbit()
- componentOrbit.period = random.uniform(0.1, 3) / daysYear
- componentOrbit.incl = random.uniform(0,360)
- componentOrbit.eccen = randomGenerator(0, 0.1)
- componentOrbit.argof = random.uniform(0,360)
- componentOrbit.ascen = random.uniform(0,360)
- componentOrbit.refplane = 'Equator'
- binary.componentorbit = componentOrbit
- return binary.print()
- with open(FileName, 'w') as outputfile:
- outputfile.write('// Asteroids made with AsteroidsRingMaker\n// {0}'.format(datetime.today()))
- for count in range(NumberOfAster):
- orbit = Orbit()
- orbit.semi = randomGenerator(InnerRadius, OuterRadius)
- orbit.incl = randomGenerator(-MaxInclination, MaxInclination)
- orbit.eccen = randomGenerator(MinEccentricity, MaxEccentricity)
- orbit.argof = random.uniform(0,360)
- orbit.ascen = random.uniform(0,360)
- orbit.refplane = 'Ecliptic'
- outputfile.write('\n\n')
- if random.random() > ChanceOfBinary:
- outputfile.write(makeAsteroid(count+1, orbit))
- else:
- outputfile.write(makeBinaryAsteroid(count+1, orbit))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement