Last active
November 15, 2016 23:03
-
-
Save benrules2/e910517b6878197388208e0974db574f to your computer and use it in GitHub Desktop.
Single Body Acceleration Calculation
This file contains 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 calculate_single_body_acceleration(bodies, body_index): | |
G_const = 6.67408e-11 #m3 kg-1 s-2 | |
acceleration = point(0,0,0) | |
target_body = bodies[body_index] | |
for index, external_body in enumerate(bodies): | |
if index != body_index: | |
r = (target_body.location.x - external_body.location.x)**2 + (target_body.location.y - external_body.location.y)**2 + (target_body.location.z - external_body.location.z)**2 | |
r = math.sqrt(r) | |
tmp = G_const * external_body.mass / r**3 | |
acceleration.x += tmp * (external_body.location.x - target_body.location.x) | |
acceleration.y += tmp * (external_body.location.y - target_body.location.y) | |
acceleration.z += tmp * (external_body.location.z - target_body.location.z) | |
return acceleration |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment