Monday, May 28, 2012

Space Voyage Part 2

     The purpose of this lab is to model a satellite trajectory as it passes by the earth and moon. This program will consist of a loop that calculates the gravitational forces acting on the satellite, change in momentum of the craft, and change in position of the satellite. If the program is successful, many different trajectories can be modeled by changing the initial conditions. For the purposes of this lab, the main target trajectory will be a figure eight.



The following is the completed and working form of the program code and a video of the program running.

 #Physics 4A Lab: Space Voyage Lab Part 1
#April 12th 2012
#Chris Cosio
#This is the first part to a space voyage simulaion.
from __future__ import division
from visual import*

scene.width =800
scene.height = 800

#CONSTANTS
G = 6.7e-11
mEarth = 6.7e24
mcraft = 15e3
mMoon = 7e22
deltat = 1
#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,5078,0)
#3050
pcraft = vcraft*mcraft
t = 0
#CALCULATION LOOP: ALL REPEATED CALCULATIONS GO INSIDE THE LOOP
while t < 10*365*24*60*60:
   rate(30000) ## slow down motion to make animation look nicer
   r_E = craft.pos-Earth.pos # craft position vector
   pvector.pos = craft.pos # momentum arrow
   r_Emag = mag(r_E)# magnitude of vector r
   rhat_E = norm(r_E) # unit vector in r direction
   F_grav_mag_E=G*mcraft*mEarth/(r_Emag**2)# magnitude of gravitational force
   F_Egrav=-F_grav_mag_E*rhat_E # gravitational force
   r_M = craft.pos-Moon.pos # craft position vector
   r_Mmag = mag(r_M)# magnitude of vector r
   rhat_M = norm(r_M) # unit vector in r direction
   F_grav_mag_M=G*mcraft*mMoon/(r_Mmag**2)# magnitude of gravitational force
   F_Mgrav=-F_grav_mag_M*rhat_M # gravitational force
   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
   t = t+deltat



      The computational model was successful in depicting different trajectories of the satellite as the initial conditions were changed. There are a few things to consider in this loop other than the physics principles. The time intervals in which the calculations occur greatly affect the accuracy of the program. The theoretical values of the initial velocity might predict a figure eight orbit; however, using that velocity might produce a less than optimal orbit based on the delta t set up in the program. If delta t is very small, then the program will produce a highly accurate trajectory. The draw back to a small delta t is that the program run time increases relative to the smallness of delta t. On the other hand, the simulation will run quicker with larger delta t values. Some notable physical observations about the trajectory is the velocity of the satellite throughout the motion. The satellite's initial velocity can change the trajectory so much that the object might not even come close to the moon or the object could end up in a elliptical orbit around the earth. As the object is subjected to impulse, the momentum changes which in turn changes the velocity. The velocity of the satellite is the lowest as it approaches a point very far from the earth; however, the object is caught in the gravitational field of the moon and starts to pick up speed again. This implies that the object lost so much initial momentum that the impulse from the moon caused a change from the elliptical orbit to the figure eight orbit.

No comments:

Post a Comment