![]() |
Orbit and graphs of the different types of energy. |
The following is the working code of the program and a video of the potential/kinetic energy graphs for the satellite. A video of the orbit corresponding to the graphs will also be included.
#Physics 4A Lab: Space Voyage Lab Part 1
#April 12th 2012
#Chris Cosio
#This is the first part to a space voyage simulation.
from __future__ import division
from visual import*
from visual.graph import*
scene.y=400
scene.width =800
scene.height = 800
#CONSTANTS
G = 6.7e-11
mEarth = 6.7e24
mcraft = 15e3
mMoon = 7e22
deltat = 390
#OBJECTS AND INITIAL VALUES
Earth = sphere(pos=vector(0,0,0), radius=6.4e6, color=color.cyan)
Moon = sphere(pos=vector(4e8,0,0), radius=1.75e6, color=color.white)
craft = sphere(pos=vector(-5*Earth.radius, 0,0), radius=1e6, color=color.yellow)
trail = curve(color=craft.color) ## for leaving a trail behind the craft
pvector = arrow(color=color.red)
vcraft = vector(0,5077.5,0)
#3050 is a good velocity for an elliptical orbit
pcraft = vcraft*mcraft
t = 0
Kgraph = gcurve(color=color.yellow)
Ugraph = gcurve(color=color.red)
KplusUgraph = gcurve(color=color.cyan)
#CALCULATION LOOP: ALL REPEATED CALCULATIONS GO INSIDE THE LOOP
while t < 10*365*24*60*60:
rate(1000000) ## slow down motion to make animation look nicer
pvector.pos = craft.pos # momentum arrow
r_E = craft.pos-Earth.pos # Earth-Craft position vector
r_Emag = mag(r_E)# magnitude of Earth-Craft position Vector
rhat_E = norm(r_E) # unit vector for r in Earth-Craft direction
F_grav_mag_E=G*mcraft*mEarth/(r_Emag**2)# magnitude of gravitational force from Earth-Craft system
F_Egrav=-F_grav_mag_E*rhat_E # gravitational force from Earth-Craft system,
r_M = craft.pos-Moon.pos # Moon-Craft position vector
r_Mmag = mag(r_M)# magnitude of Moon-Craft position vector r
rhat_M = norm(r_M) # unit vector for r in Moon-Craft direction
F_grav_mag_M=G*mcraft*mMoon/(r_Mmag**2)# magnitude of gravitational force from Moon-Craft system
F_Mgrav=-F_grav_mag_M*rhat_M # gravitational force from Moon-Craft system
vcraft = vcraft+(F_Egrav/mcraft)*deltat+(F_Mgrav/mcraft)*deltat # craft velocity
pcraft = pcraft+F_Egrav*deltat+F_Mgrav*deltat # craft momentum
pvector.axis = 1*pcraft
craft.pos = craft.pos + (pcraft/mcraft)*deltat
trail.append(pos=craft.pos) ## this leaves a trail behind the spacecraft
K = 0.5*mcraft*mag(vcraft)**2 #Kinetic Energy
U = F_grav_mag_E*r_Emag+F_grav_mag_M*r_Mmag #Potential Energy
Kgraph.plot(pos=(t,K)) #Kinetic Energy plot
Ugraph.plot(pos=(t,U)) #Potential Energy Plot
KplusUgraph.plot(pos=(t,K+U)) #Total Mechanical Energy Plot
t = t+deltat
The graphs depict total energy (blue), kinetic energy (yellow), and potential energy from the earth/moon (red). As the satellite gets closer to the earth the gravitational potential increases with the acceleration increase; however, there is a trade off with the distance between the satellite and the earth/moon where being too close would eventually cause a decrease in potential energy. As the satellite reaches a three fourths point between the earth and moon, the kinetic energy becomes relatively low as well as the potential energies. This is due to the net forces acting on the satellite at this point being very small. The graph depicts a few local maximums when it is closes to the moon, and one absolute maximum when it is closest to the earth. If the time interval is changed past a certain value to speed up the program, the orbit becomes inaccurate and the program can even fail. The program failing is evident by the earth or moon sling shooting the satellite away at an escape velocity.
No comments:
Post a Comment