Skip to content

Commit

Permalink
laying out orbital
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Jun 25, 2014
1 parent 268ae3a commit 462ef78
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Exercises/ClassicalMechanics/Orbital/Python/orbital.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
############################################################
# Martian Invasion
############################################################

# Import 'numpy' for numerical calculations, vectors, etc.
import numpy as np
from numpy.linalg import norm as norm

# Import our parameter file, the '*' says take everything in that
# file, and make it available for use in this file
from params import *

def force_gravity(r1, r2, m1, m2):
r = r2 - r1
F = - G*m1*m2*norm(r)**(-3.)*r
return F


# Calculate the forces on the current system
def calculate_forces(positions):
print "force"

# Update the positions using verlet integration
def update_pos(positions, velocities):
print "verlet"


def main():
print "Starting calculation."

# positions is an array of vectors in a 2D plane specifying the
# positions of [sun, earth, mars, rocket]
positions = np.array([
[0, 0],
[RADIUS_E, 0],
[RADIUS_M, 0],
[RADIUS_M + RADIUS_R, 0],
])

masses = np.array([MASS_S, MASS_E, MASS_M, MASS_R])

print force_gravity(positions[0], positions[1],
masses[0], masses[1])

# This is Python syntax which tells Python to call the function we
# made called 'main()' only if this file was run directly rather than
# with 'import orbital'
if __name__ == "__main__":
main()

18 changes: 18 additions & 0 deletions Exercises/ClassicalMechanics/Orbital/Python/params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
############################################################
# Constants and initial parameters for Martian invasion
############################################################

dt = 1
G = 6.67e-11 # Gravitational constant [N m^2/kg^2]

RADIUS_E = 1.521e11 # Earth to sun [meters]
RADIUS_M = 2.296e11 # mars to sun [meters]
RADIUS_R = 4.256e5 # Mars to rocket orbit [meters]

MASS_S = 1.989e30 # Mass of the Sun [kg]
MASS_E = 5.972e24 # Mass of Earth [kg]
MASS_M = 6.417e23 # Mass of Mars [kg]
MASS_R = 4.500e5 # Mass of rocket [kg]

VEL_E = 2.98e4 # Velocity of Earth [m/s]
VEL_M = 2.41e4 # Velocity of Mars [m/s]
Binary file not shown.

0 comments on commit 462ef78

Please sign in to comment.