space_voyage - ## gravitational force, momentum, and...

Info iconThis preview shows pages 1–2. 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 s #CONSTANTS G = 6.7e-11 mEarth = 6e24 mcraft = 15e3 deltat = 60 pscale = .25 fscale = 1e3 dpscale = 20 d #OBJECTS AND INITIAL VALUES Earth = sphere(pos=vector(0,0,0), radius=6.4e6, color=color.cyan) scene.range=11*Earth.radius # Choose an exaggeratedly large radius for the # space craft so that you can see it! craft = sphere(pos=vector(-74240000,5568000,0),radius=2e6, color=color.yellow) vcraft = vector(653,2759,0) pcraft = mcraft*vcraft parr = arrow(color=color.green) farr = arrow(color=color.cyan) dparr = arrow(color=color.red) d 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 s #CALCULATIONS tf = 79200 t while t < tf: #rate(1000) ## slow down motion to make animation look nicer ## you must add statements for the iterative update of
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ## gravitational force, momentum, and position r = craft.pos - Earth.pos rmag = mag(r) Fmag = (G*mcraft*mEarth)/rmag**2 rhat = r/rmag Fnet = -Fmag*rhat pcrafti = pcraft + vector(0,0,0) pcraft = pcraft + Fnet*deltat deltap = pcraft - pcrafti craft.pos = craft.pos + (pcraft/mcraft)*deltat parr.pos = craft.pos parr.axis = pcraft*pscale farr.pos = craft.pos farr.axis = Fnet*fscale dparr.pos = craft.pos dparr.axis = deltap*dpscale ## 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 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' print 'Final position =', craft.pos print 'Final velocity=', pcraft/mcraft print 'Gravitational Force=', Fnet...
View Full Document

Page1 / 2

space_voyage - ## gravitational force, momentum, and...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online