Last active
November 16, 2016 16:34
-
-
Save benrules2/42b6437d82f6851ac6574a9390987824 to your computer and use it in GitHub Desktop.
Python N-Body Orbit Simulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #planet data (location (m), mass (kg), velocity (m/s) | |
| sun = {"location":point(0,0,0), "mass":2e30, "velocity":point(0,0,0)} | |
| mercury = {"location":point(0,5.7e10,0), "mass":3.285e23, "velocity":point(47000,0,0)} | |
| venus = {"location":point(0,1.1e11,0), "mass":4.8e24, "velocity":point(35000,0,0)} | |
| earth = {"location":point(0,1.5e11,0), "mass":6e24, "velocity":point(30000,0,0)} | |
| mars = {"location":point(0,2.2e11,0), "mass":2.4e24, "velocity":point(24000,0,0)} | |
| jupiter = {"location":point(0,7.7e11,0), "mass":1e28, "velocity":point(13000,0,0)} | |
| saturn = {"location":point(0,1.4e12,0), "mass":5.7e26, "velocity":point(9000,0,0)} | |
| uranus = {"location":point(0,2.8e12,0), "mass":8.7e25, "velocity":point(6835,0,0)} | |
| neptune = {"location":point(0,4.5e12,0), "mass":1e26, "velocity":point(5477,0,0)} | |
| pluto = {"location":point(0,3.7e12,0), "mass":1.3e22, "velocity":point(4748,0,0)} | |
| if __name__ == "__main__": | |
| #build list of planets in the simulation, or create your own | |
| bodies = [ | |
| body( location = sun["location"], mass = sun["mass"], velocity = sun["velocity"], name = "sun"), | |
| body( location = earth["location"], mass = earth["mass"], velocity = earth["velocity"], name = "earth"), | |
| body( location = mars["location"], mass = mars["mass"], velocity = mars["velocity"], name = "mars"), | |
| body( location = venus["location"], mass = venus["mass"], velocity = venus["velocity"], name = "venus"), | |
| ] | |
| motions = run_simulation(bodies, time_step = 100, number_of_steps = 80000, report_freq = 1000) | |
| plot_output(motions, outfile = 'orbits.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment