Skip to content

Instantly share code, notes, and snippets.

@uhho
Created June 18, 2018 23:36
Show Gist options
  • Save uhho/494820d0badd031d992fe11651caa799 to your computer and use it in GitHub Desktop.
Save uhho/494820d0badd031d992fe11651caa799 to your computer and use it in GitHub Desktop.
Gravitational accelleration
def g_at_distance(g_base, radius, distance):
"""
Calculate gravitational accelleration at a distance
- above the surface G * (radius / distance)^2
- below the surface G * (distance / radius)
Parameters
----------
g_base : float
gravitational accelleration at the surface
radius : int, float
surface radius
distance : ndarray
array of distances from the center of mass
Returns
-------
g : ndarray
Gravitational accelleration at a distance
"""
above = np.divide(radius, distance, where=distance != 0) ** 2
below = (distance / radius)
g = g_base * np.where(distance < radius, below, above)
return g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment