Tuesday, February 4, 2014

Physics Force Accumulation

I've been working on a solar system simulation.

It went okay. The basics are all in place, I can add bodies, and add gravitational forces per-body. (Right now things are only attracted to the sun, because those are the only non-negligible forces in the system, but multiple forces are fully supported.)

The devil's in the details, though.

The numbers involved are too large and require too much precision for my Vector data type, which uses floats. I've done what I can in that department by choosing good units, my distances are in Light Minutes, my masses are in 10^24 Grams. However, my gravitational constant is wrong, and no amount of tinkering to compensate for errors makes it work right. I can find values where planets in a certain size range orbit more or less properly, but lighter planets than that range take off into space, and heavier planets develop super-elliptical slingshot orbits that would destroy a real planet. (As you see in the video, Jupiter's orbit takes it through the surface of the sun at four or five times intended heliocentric velocity.) I almost think there's a formula wrong somewhere, but I can't find it, and fortunately this one problem is in a very minor part of the spec. 

All my auxiliary features are in place; I can zoom on planets, and dynamically add planets, and display particle trails for orbits. I can draw debug info, although I can't figure out how to draw it at a planet's location, or at any size smaller than 48pt. I can reset the simulation freely.

Here's a video of it in action, although Youtube mangled it pretty badly, so you'll have to squint at the smaller planets.