Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from vpython import *
- import numpy as np
- #Earth-Moon gravity EMmulation
- #IMPORTANT CONSTANTS
- G = 6.67e-11 #Newton's Constant
- EM = 6e24 #Earth's Mass
- MM = 7e22 #Moon's Mass
- ER = 6.3e6 #Earth's Radius
- MR = 1.7e6 #Moon's Radius
- Distance = 3.8e8
- Earth = sphere(pos = vector(0,0,0), radius = ER, color = color.blue)
- Earth.m = EM
- Earth.v = vector(0,0,0) #Velocity
- Earth.p = Earth.m*Earth.v #Momentum
- Moon = sphere(pos = vector(Distance,0,0), radius = MR, color = vector(0.5,0.5,0.5), make_trail=True)
- Moon.m = MM
- Moon.v = vector(0,np.sqrt(G*Earth.m/Distance),0)
- Moon.p = Moon.m*Moon.v
- dt = 0.01
- while True:
- Vec = Earth.pos + Moon.pos
- Fg = -G*Earth.m*Moon.m/mag(Vec)**3*Vec #Vector form of the Gravity Equation
- # 1. We will update the momentum according to Pf = FΔt + Pi
- Earth.p = -Fg*dt + Earth.p
- Moon.p = Fg*dt+Moon.p #-Fg becDistancese forces are equal and opposite
- #2. Update the velocites of each object, p = mv, so v = m/p
- Earth.v = Earth.p/Earth.m
- Moon.v = Moon.p/Moon.m
- #3. Update the positions
- Earth.pos = Earth.pos+Earth.v
- Moon.pos = Moon.pos+Moon.v
- print("Vector Velocity: ",Moon.v,"Magnitutde: ",mag(Moon.v))
- rate(10000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement