Lab 05 - SpaceVoyage1

Lab 05 - SpaceVoyage1 - ## slow down motion to make...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
from __future__ import division from visual import * scene.width =1024 scene.height = 760 #CONSTANTS G = 6.7e-11 mEarth = 6e24 mcraft = 15e3 deltat = 60 pscale = .5 #OBJECTS AND INITIAL VALUES Earth = sphere(pos=vector(0,0,0), radius=6.4e6, color=color.cyan) # Choose an exaggeratedly large radius for the # space craft so that you can see it! craft = sphere(pos=vector(-10*Earth.radius, 0,0), radius=3.2e6, color=color.yellow) vcraft = vector(0,1500,0) pcraft = mcraft*vcraft parr = arrow(color=color.green) r = craft.pos - Earth.pos rmag = sqrt(r.x**2 + r.y**2 + r.z**2) rhat = r / rmag trail = curve(color=craft.color) ## craft trail: starts with no points t = 0 scene.autoscale = 0 ## do not allow camera to zoom in or out #CALCULATIONS while t < 10*365*24*60*60: rate(200)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ## slow down motion to make animation look nicer ## you must add statements for the iterative update of ## gravitational force, momentum, and position r = craft.pos - Earth.pos rmag = sqrt(r.x**2 + r.y**2 + r.z**2) rhat = r / rmag gforce = -(G * mEarth * mcraft) / rmag**2 gvector = gforce * rhat pcraft = pcraft + gvector*deltat craft.pos = craft.pos + (pcraft/mcraft)*deltat ## check to see if the spacecraft has crashed on the Earth. ## if so, get out of the calculation loop if rmag &lt; Earth.radius: break parr.pos = craft.pos parr.axis = pcraft * pscale trail.append(pos=craft.pos) ## this adds the new position of the spacecraft to the trail t = t+deltat print 'Calculations finished after ',t,'seconds'...
View Full Document

Ask a homework question - tutors are online