Pages

Sunday, May 19, 2019

Intelligent Falling

[Title refers to the equally credible explanation for gravity.]

I'm in the middle of reading Seveneves, by Neal Stephenson, which involves humanity fleeing the surface of Earth to survive in orbit. All the discussion of orbital mechanics reminded me of a program I loved playing with when I was growing up called Gravitation, Ltd. It let you set up bodies of different masses in space, and let them move according to each other's gravity. What I particularly liked seeing was the different patterns the orbits would make. Since that application is more than 20 years old at this point, I was curious if I could set up another HTML5 widget to play with.

For any pair of objects, Newton's Law gives the acceleration of one object created by the other:
where G is Newton's constant, m is the mass of the attracting object, and r is the vector from the accelerating object to the attracting one. This is a second-order differential equation for the position of the body: The equation gives an acceleration, which is the change in velocity, which is the change in position. At every step of time in our simulation, we need to find the acceleration, and from that get the velocity and position. The natural way to do that, integrating up from acceleration, would be
where the subscript indicates the step number. This is called Forward Euler Integration. For certain systems though, this method can be unstable, producing results that diverge to infinity. A more robust technique is Backward Euler Integration, which does the calculation in the opposite order:
Both are implemented below, but I haven't noticed much difference for the cases I've tried. Play around a bit, and be sure to post interesting settings in the comments!

Canvas not supported; please update your browser.

Initial Position


Initial Velocity


Star Mass


Method


No comments:

Post a Comment