Created
December 1, 2015 04:45
-
-
Save danimaribeiro/3055f6a03991745835a7 to your computer and use it in GitHub Desktop.
Simulação do sol orbitando o centro da galaxia e a terra orbitando o sol em um plano de 60 graus em relação ao plano da galaxia.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Created on 1 de dez de 2015 | |
@author: danimar | |
''' | |
from visual import sphere, materials, color, vector, display,\ | |
rate, mag, radians | |
from visual.graph import * | |
scene = display(width=1800, height=900, center=(0, 5, 0)) | |
sun = sphere(pos=(-3000, 0, 0), radius=50, color=color.orange, | |
make_trail=True) | |
p_earth = vector(-3200, 0, 0) | |
earth = sphere(pos=p_earth, | |
radius=10, | |
material=materials.earth, | |
make_trail=True) | |
milk_way = sphere(pos=(0, 0, 0), radius=50, color=color.magenta) | |
earthv = vector(0, 0, 28).rotate(angle=radians(60), axis=(1,0,0)) | |
sunv = vector(0, 0, 8) | |
gd = gdisplay(x=800, y=0, width=600, height=600, | |
foreground=color.black, background=color.white, | |
xmax=3000, xmin=0, ymax=20, ymin=0) | |
f1 = gcurve(color=color.red) | |
t = 0 | |
for i in range(6000): | |
rate(80) | |
# Sun orbit | |
distsun = ((sun.x - milk_way.x)**2 + (sun.y - milk_way.y) | |
** 2 + (sun.z - milk_way.z)**2)**0.5 | |
radialVectorSun = (sun.pos - milk_way.pos) / distsun | |
FgravitationSun = (-200000 * radialVectorSun) / (distsun**2) | |
sunv = sunv + FgravitationSun | |
sun.pos += sunv | |
# Earth orbit | |
#earth.pos = earth.pos + earthv | |
dist = ((earth.x - sun.x)**2 + (earth.y - sun.y) | |
** 2 + (earth.z - sun.z)**2)**0.5 | |
radialVector = (earth.pos - sun.pos) / dist | |
Fgravitation = (-100000 * radialVector) / (dist**2) | |
earthv = earthv + Fgravitation | |
earth.pos += earthv | |
f1.plot(pos=(t, mag(earthv))) | |
t += 1 | |
if dist <= sun.radius: | |
break | |
if distsun <= milk_way.radius: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment