0

I'm wondering whats the easiest way to apply gravity at the center of a sphere (much like a planet) I'm thinking that ODE would be the best library to use? But not sure on how to implement it to apply the gravity at the center of the sphere.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Elgoog
  • 2,205
  • 7
  • 36
  • 48

1 Answers1

4

All you need is :

a = F/m = -GM r/r^3

where r is the radial vector for the mass m from the Sphere of mass M and G is the Gravitational constant.

You don't necessarily need much of a library to integrate this. You can just compute acceleration for each time step. The only point is that you get a much better result (E.g. closed orbits!) if for each step you first compute an approximate new position, then compute the acceleration for the location at mid-point of the timestep and then use that to determine the new position and velocity.

Keith
  • 6,756
  • 19
  • 23
  • Isn't r supposed to be squared instead of cubed? – num3ric Mar 31 '11 at 04:55
  • 1
    num3ric: Look closer. It's \vec r/r^3, i.e. this does vector normaliyation and 1/r^2 falloff in a single expression. This is the typical notation used by pysicists. – datenwolf Mar 31 '11 at 13:08