|
From: Symion <sy...@pr...> - 2008-03-26 01:39:23
|
Hi there,
Reading through the messages from the mailing list, I've noticed
that a number of people are using Vpython for astronomical simulations.
Here is another program that puts most of the necessary data into a
single list so as to produce a scaled representation of The Solar System.
It includes all planets and most of the major moons. These are lined
up so that easy comparisons can be made between each object.
All data has been researched from online sources (JPL, NASA, The
Wiki), so hopefully everything is correct.
The original reason for writing this program came from a
conversation I had with someone who refused to accept Solar Energy as a
viable solution to our energy needs. It really annoyed me that he seemed
unable to comprehend just how big the Sun really is!
So lets hope this program doesn't fall over and may be useful to those
fellow astronomy buffs.
Controls are simply point and click.
Cheers
from __future__ import division
from visual import *
from random import *
'''Welcome to The Solar System - (c) 2008 Symion'''
class Solar:
'''Compare Astronomical Objects'''
def __init__(self, o=(0,0,0), r=1.0, c=(1,1,1)):
self.orbit=o
self.radius=r
self.color=c
sphere(pos=o,radius=r,color=c)
## data contains name,radius coefficient ,orbital coefficient,mass
coefficient,color
Data=[['Sol',1.09088e+002,0.00000e+000,3.33166e+005,(3.0,3.0,0.0)],
['Mercury',3.82985e-001,3.87099e-001,5.52764e-002,(0.5,0.5,0.5)],
['Venus',9.49929e-001,7.23262e-001,8.15745e-001,(0.9,0.4,0.5)],
['Earth',1.00000e+000,1.00000e+000,1.00000e+000,(0.2,0.2,1.0)],
['Luna',2.72799e-001,1.00000e+000,1.67219e-002,(0.4,0.4,0.4)],
['Mars',5.33276e-001,1.52366e+000,1.07538e-001,(1.0,0.2,0.0)],
['Jupiter',1.12215e+001,5.20274e+000,3.18258e+002,(0.4,0.3,0.1)],
['Io',2.85826e-001,5.20274e+000,1.49615e-002,(0.5,0.3,0.0)],
['Europa',2.45644e-001,5.20274e+000,8.04020e-003,(0.6,0.6,0.9)],
['Ganymede',4.13436e-001,5.20274e+000,2.48074e-002,(0.6,0.6,0.5)],
['Callisto',3.77178e-001,5.20274e+000,1.80067e-002,(0.7,0.7,0.9)],
['Saturn',9.45982e+000,9.55481e+000,9.51424e+001,(0.8,0.6,0.1)],
['Titan',4.04175e-001,9.55481e+000,2.26131e-002,(0.6,0.5,0.9)],
['Rhea',1.19918e-001,9.55481e+000,3.86935e-004,(0.5,0.6,0.7)],
['Uranus',4.01185e+000,1.91911e+001,1.45394e+001,(0.2,0.2,0.7)],
['Titania',1.23842e-001,1.91911e+001,5.91290e-004,(0.6,0.6,0.9)],
['Oberon',1.19447e-001,1.91911e+001,5.04355e-004,(0.5,0.6,0.7)],
['Neptune',3.88730e+000,3.01090e+001,1.70854e+001,(0.1,0.4,0.8)],
['Triton',2.12369e-001,3.01090e+001,3.60134e-003,(0.2,0.5,0.8)],
['Pluto',1.80505e-001,3.95289e+001,2.12730e-003,(0.6,0.6,0.9)],
['Charon',9.51185e-002,3.95289e+001,3.18258e-004,(0.4,0.4,0.4)]]
'''
['Ring',1.38487e+001,9.55481e+000,9.66332e-001,(0.5,0.6,0.7)],
['Asteroids',8.63915e+005,0.00000e+000,1.24288e+000,(0.2,0.2,0.2)]]
'''
## Define Constants
G=6.6732e-11
AU=1.496e+011
ER=6.371e+06
EM=5.970e+024
## Setup the Graphic Window
scene.visible=0
scene.x=100
scene.y=100
x=scene.x+scene.width
y=scene.y
scene.title='Compare The Sun with The Planets - (c) 2008 Symion'
scene.background=(0.0,0.05,0.15)
scene.lights=[vector(-3,0,0)]
scene.ambient=.5
## Start with The Sun
## Pre calculate Radii & Distance
radii=[Data[0][1]*ER]
distance=[vector(0,0,0)]
loc=distance[0]+vector(radii[0],0,0)
for v in Data[1:]:
radii.append(v[1]*ER)
loc=loc+vector(radii[-1],0,0)
distance.append(loc)
loc=loc+vector(radii[-1],0,0)
## Do the Deed
sol=Solar(o=distance[0],r=radii[0],c=Data[0][4])
mercury=Solar(o=distance[1],r=radii[1],c=Data[1][4])
venus=Solar(o=distance[2],r=radii[2],c=Data[2][4])
earth=Solar(o=distance[3],r=radii[3],c=Data[3][4])
luna=Solar(o=distance[4],r=radii[4],c=Data[4][4])
mars=Solar(o=distance[5],r=radii[5],c=Data[5][4])
jupiter=Solar(o=distance[6],r=radii[6],c=Data[6][4])
io=Solar(o=distance[7],r=radii[7],c=Data[7][4])
europa=Solar(o=distance[8],r=radii[8],c=Data[8][4])
ganymede=Solar(o=distance[9],r=radii[9],c=Data[9][4])
callisto=Solar(o=distance[10],r=radii[10],c=Data[10][4])
saturn=Solar(o=distance[11],r=radii[11],c=Data[11][4])
titan=Solar(o=distance[12],r=radii[12],c=Data[12][4])
rhea=Solar(o=distance[13],r=radii[13],c=Data[13][4])
uranus=Solar(o=distance[14],r=radii[14],c=Data[14][4])
titania=Solar(o=distance[15],r=radii[15],c=Data[15][4])
oberon=Solar(o=distance[16],r=radii[16],c=Data[16][4])
neptune=Solar(o=distance[17],r=radii[17],c=Data[17][4])
triton=Solar(o=distance[18],r=radii[18],c=Data[18][4])
pluto=Solar(o=distance[19],r=radii[19],c=Data[19][4])
charon=Solar(o=distance[20],r=radii[20],c=Data[20][4])
scene.visible=1
scene.autoscale=0
## Define other Window
work=display(title='Information Window',
width=300,
height=250,
center=(0,0,0),
background=(0.5,0.5,0.5))
## Choose the index for the initial Object of Focus
n=0
work.userzoom=0
work.userspin=0
work.x=x
work.y=y
## Fancy border
curve(pos=[(-1,-1),(-1,1),(1,1),(1,-1),(-1,-1)],color=(0,0,0))
curve(pos=[(-1.1,-1.1),(-1.1,1.1),(1.1,1.1),(1.1,-1.1),(-1.1,-1.1)],color=(1,1,1))
cube=box(pos=((-1,-1,0)),width=0.1,height=0.1,length=0.1,color=(1,0,0))
work.forward=vector(0,0,-1)
## Initialize Data Window
s=Data[n][0]+'\nOrbit %0.3e m\nRadius %0.3e m\nMass %0.3e kg\ng %0.5f
m/s/s\nEscape V %0.4f km/s'
%(Data[n][2]*AU,radii[n],Data[n][3]*EM,(G*Data[n][3]*EM)/(radii[n]**2),sqrt((2*G*Data[n][3]*EM)/(radii[n]))/1000.0)
label(pos=(0,-0.4), opacity=1, font='Courier', height=9, color=(1,1,1),
box=1, text=s)
work.autoscale=0
## User Input: Choose an Object
count=0.0
while 1:
rate(50)
cube.rotate(angle=radians(5),axis=(sin(count),.5,.5))
if scene.mouse.events>0:
m=scene.mouse.getevent()
if m.release:
if m.pick:
o=m.pick
scene.center=o.pos
n=o.display.objects.index(o)
if n>-1 and n<len(Data):
work.objects[-1].visible=0
s=Data[n][0]+'\nOrbit %0.3e m\nRadius %0.3e m\nMass %0.3e
kg\ng %0.5f m/s/s\nEscape V %0.4f km/s'
%(Data[n][2]*AU,radii[n],Data[n][3]*EM,(G*Data[n][3]*EM)/(radii[n]**2),sqrt((2*G*Data[n][3]*EM)/(radii[n]))/1000.0)
label(pos=(0,-0.4), opacity=1, font='Courier', height=9,
color=(1,1,1), box=1, text=s)
else:
pass
else:
p=scene.mouse.pos
scene.center=p
else:
pass
elif work.mouse.events>0:
m=work.mouse.getevent()
if m.release:
if m.pick:
count+=.1
cube.color=(abs(sin(count)),abs(cos(count)),abs(sinh(count)))
else:
pass
else:
pass
else:
pass
|