Template:Hidden: Difference between revisions

From Physics Book
Jump to navigation Jump to search
(Created page with "from __future__ import division from visual import * from visual.graph import * scene.width=1024 scene.height=760 # CONSTANTS G = 6.7e-11 mEarth = 6e24 mcraft = 15000 deltat...")
 
(Blanked the page)
 
Line 1: Line 1:
from __future__ import division
from visual import *
from visual.graph import *
scene.width=1024
scene.height=760


# CONSTANTS
G = 6.7e-11
mEarth = 6e24
mcraft = 15000
deltat = 60
t = 0
mMoon = 7e22
scale = 800000
c=2.99792e8
#OBJECTS AND INITIAL VALUES
Earth = sphere(pos=vector(0,0,0), radius=15e6, material = materials.BlueMarble)
# Add a radius for the spacecraft. It should be BIG, so it can be seen.
craft = sphere(pos=vector(-60160000,-192000,0), radius=2e6, material = materials.marble)
Moon =  sphere(pos=vector(4e8,0,0), radius=1.75e6, material = materials.marble)
vcraft = vector(735,2849,0)
pcraft = mcraft*vcraft
trail = curve(color=craft.color)    # This creates a trail for the spacecraft
#scene.autoscale = 1000000                # And this prevents zooming in or out
pscale = Earth.radius / mag(pcraft)
fscale = Earth.radius/ ((G*mEarth*mcraft)/mag(craft.pos-Earth.pos)**2)
dpscale = 500 * Earth.radius/mag(pcraft)
r_EarthMoon = Moon.pos - Earth.pos #Relative position vector from Earth to Moon
r_EarthMoon_mag = mag(r_EarthMoon)
F_EarthMoon_mag = (G*mcraft*mEarth)/(r_EarthMoon_mag**2)
r_EarthMoon_hat = r_EarthMoon/r_EarthMoon_mag
Force_EarthMoon = (-r_EarthMoon_hat)*F_EarthMoon_mag #Force on Moon due to Earth
pMoon = Force_EarthMoon / deltat
# CALCULATIONS
print("p=",  pcraft)
while t < (10e10):
    rate(500)  # This slows down the animation (runs faster with bigger number)
    rE =  craft.pos - Earth.pos
    rEmag = mag(rE)
    FEmag = (G*mcraft*mEarth)/(rEmag**2)
    rEhat = rE/rEmag
    FEnet = (-rEhat)*FEmag
    rM =  craft.pos - Moon.pos
    rMmag = mag(rM)
    FMmag = (G*mcraft*mMoon)/(rMmag**2)
    rMhat = rM/rMmag
    FMnet = (-rMhat)*FMmag
   
    Fnet = FMnet+FEnet
    pcraft_i = pcraft + vector(0,0,0)
    pcraft_ii = mag(pcraft_i)   
    pcraft = pcraft + ((Fnet)*deltat)
    pcraft_f = pcraft
    pcraft_ff = mag(pcraft)
    vavg = pcraft/mcraft
    speedcraft = mag(vavg)
    craft.pos = craft.pos + vavg*deltat
    Fnet_tangent = ((pcraft_ff-pcraft_ii)/deltat)*(pcraft/mag(pcraft))*pscale
    Fnet_perp = Fnet - Fnet_tangent
    r_EarthMoon = Moon.pos - Earth.pos #Relative position vector from Earth to Moon
    r_EarthMoon_mag = mag(r_EarthMoon)
    F_EarthMoon_mag = (G*mcraft*mEarth)/(r_EarthMoon_mag**2)
    r_EarthMoon_hat = r_EarthMoon/r_EarthMoon_mag
   
    r_craftMoon = Moon.pos - craft.pos#Relative position vector from spacecraft to Moon
    r_craftMoon_mag = mag(r_craftMoon)
    F_craftMoon_mag = (G*mcraft*mEarth)/(r_craftMoon_mag**2)
    r_craftMoon_hat = r_craftMoon/r_craftMoon_mag   
    Force_EarthMoon = (-r_EarthMoon_hat)*F_EarthMoon_mag #Force on Moon due to Earth
    Force_craftMoon = (-r_craftMoon_hat)*F_craftMoon_mag#Force on Moon due to spacecraft
    Fnet_Moon = Force_EarthMoon + Force_craftMoon #Net force on Moon
    momentum_Moon = pMoon + Fnet_Moon*deltat#Update momentum of Moon
    vavg_Moon = momentum_Moon/mMoon
    Moon.pos = Moon.pos + vavg_Moon * deltat #Update momentum of Moon
    trail.append(pos=craft.pos) 
    t = t+deltat
    pcraft = pcraft_f
    deltap = pcraft - pcraft_i

Latest revision as of 22:06, 18 April 2018