For a planet with mass m , at a distance r from the ship, the ship will experience acceleration:
a = k m / r ^ 2,
where k is some constant that depends on the units you use. Acceleration will be directed toward the planet. It would be convenient to split the acceleration into its components along the x and y axes (provided that you are working in two dimensions). If the planet is at an angle theta in the xy plane relative to the ship,
a x = a cos ( theta strong>)
a y = a sin ( theta strong>)
For multiple planets, you can simply add acceleration components by component.
If the ship has an initial speed v x at time t , then the speed at the next step t + delta_t :
v x + a x * delta_t
If this vessel is in the initial position p x at time t, then the position at t + delta_t will be:
p x + v x delta_t + a x delta_t ^ 2/2
See: Equations of motion
Jim lewis
source share