Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top