Last active
November 15, 2016 23:19
-
-
Save benrules2/52d2e00cff87ca67a99d03fb54cbec34 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
| def run_simulation(bodies, names = None, time_step = 1, number_of_steps = 10000, report_freq = 100): | |
| #create output container for each body | |
| body_locations_hist = [] | |
| for current_body in bodies: | |
| body_locations_hist.append({"x":[], "y":[], "z":[], "name":current_body.name}) | |
| for i in range(1,number_of_steps): | |
| compute_gravity_step(bodies, time_step = 1000) | |
| if i % report_freq == 0: | |
| for index, body_location in enumerate(body_locations_hist): | |
| body_location["x"].append(bodies[index].location.x) | |
| body_location["y"].append(bodies[index].location.y) | |
| body_location["z"].append(bodies[index].location.z) | |
| return body_locations_hist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment