Skip to content

Instantly share code, notes, and snippets.

@benrules2
Last active November 15, 2016 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benrules2/e910517b6878197388208e0974db574f to your computer and use it in GitHub Desktop.
Save benrules2/e910517b6878197388208e0974db574f to your computer and use it in GitHub Desktop.
Single Body Acceleration Calculation
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