Demonstrating Orbits with Javascript

Click on images to start them moving.

The further a world is from its sun, the slower it needs to move to stay in orbit. For a circular orbit, Velocityworld = sqrt(masssun/distance). Kinetic energy = 0.5*massworld*velocity2. Since velocity is proportional to 1/distance, the kinetic energy required for a circular orbit goes to infinity as the distance goes to zero.

The period of a world (how long an orbit takes) in a circular orbit is 2*pi*radius/velocity, and velocity is proportional to sqrt(1/radius), so the period is proportional to radius3/2. That's Kepler's third law of orbits. For example (as in the inner and outer worlds in the example), a world at 4 times the distance should have a period that takes 8 times as long, despite going only 4 times the distance.

The position and absolute velocity determine the period of an orbit. Direction does not matter.
Escape velocity requires twice the energy, thus sqrt(2) times the speed, of a circular orbit. Equivalently, if a world at distance x is in a circular orbit, a world at distance 2x going at the same speed is going at escape velocity.

A world at rest at distance infinity has escape velocity. The kinetic energy of a world going at escape velocity is equal to the potential energy lost because of being close to a sun. Since the kinetic energy of escape velocity is twice that of a circular orbit, and the kinetic energy required for a circular orbit approaches infinity as distance goes to zero, we see that the maximum potential energy that can be lost is infinite. Potential energy has to be measured as a negative quantity, with zero being the potential energy of a world at rest at distance infinity.

The potential energy between two worlds is -mass1*mass2/distance1,2. (The potential energy between n particles is the sum of that same formula for all particles i,j where i is not j). The kinetic energy energy of two particles is 0.5*mass1*velocity12 + 0.5*mass2*velocity22. Total energy is kinetic plus potential energy.

The total energy of a system remains constant. Momentum is conserved. Angular momentum about the center of gravity is also conserved.

Any polynomial extrapolation of orbits will fail dramatically when two worlds collide. Acceleration approaches infinity as distance approaches zero. When a sample point has distance close to zero, the extrapolation used by the simulation will assume that that this tremendous acceleration was applied for much more time than it really was. This isn't a real effect, it's a flaw in the simulation method. Perhaps I should fix it by having the simulation merge worlds when they get this close.
When two worlds orbit one another, the orbits of both worlds are ovals (ellipses), and the center of gravity of the two worlds is one of the focii of both ovals. (This is Kepler's first law, except he said the sun was at one of the focii. That's experimentally accurate because the sun weighs so much more than any world circling it.)

The momentums for the two worlds are equal and opposite, that is m1*v1 = -m2*v2. A world twice as heavy as another (as in this demo) will move at 1/2 the speed. Its orbit will be 1/2 the length of the lighter world. Their distances from the center of gravity will remain in proportion 1 : 2.

The kinetic energy for the two worlds, 0.5*m1*v12 and 0.5*m2*v22, are not equal. The lighter world carries most of the kinetic energy because its velocity is higher.

The worlds move faster when they are closer because potential energy has been converted to kinetic. If you attach a cord to one of the worlds and the center of gravity, then measure the area swept out by the cord in some fixed amount of time, that area is constant for all starting points on the orbit. (That's Kepler's second law.)

Try pointing the mouse at the center of gravity. (It's also the exact center of the display.) Note how the worlds keep in line with the mouse, and the proportion between their distances stays the same.

Moons in counterclockwise orbits around planets moving clockwise around their sun are inherently stable. (This demo doesn't stop itself, you have to click on it again to stop it.)
Moons orbiting at 90 degrees to planets moving clockwise around their sun are not stable. (Once the moon spins off, shift and drag to zoom, so you can see where the moon went to.)
Moons orbiting clockwise around planets moving clockwise around their sun are not stable. Our moon, orbiting our earth, seems to be in this kind of orbit. Does that mean we'll eventually lose the moon?
Let's try the other side.

Let me start the moon on the other side, and balance the parameters so the clockwise-around-clockwise stays together as long as I can make it.

Kinda spooky, huh.

I think the trick that keeps our moon stable is that the earth's gavitational well is relatively bigger than in those examples. Here, let me make the well bigger by giving the planet more mass, the moon more speed, and repeat the first clockwise-clockwise example.
Almost-planar systems eventually decay into three-dimensional systems. 3D systems remain 3D because 3D systems have more entropy. That is, there are a zillion 3D systems for every one planar system, so if one 3D system becomes almost planar, there must be a zillion minus one that remain 3D. And it also means that those systems that are almost-planar become 3D with probability a zillion minus one out of a zillion. (This one takes a while.)

But then, how do I explain that the solar system is almost planar? It must have started out that way. But how about the moons circling Jupiter and Saturn? Aren't they planar? Weren't some of them stray comets that got captured? And what about Saturn's rings, only ten miles thick? Or the asteroid belt?

It looks like friction (through small particles, fields, and collisions) is involved. If the system spins, a nonequatorial orbit without friction will precess about the equator, gradually changing from orbits that come in above the equator and go out below, to orbits whose minor axis is parallel to the equatorial plane, to orbits that go in below the equator and come out above, and back again. If there are lots of objects, any deviation from the equatorial plane will lead to collisions of one sort or another, and some of the energy will be absorbed as friction. With enough friction, everything is either ejected from the system or left in nice circular orbits in the equatorial plane.

The rings of Saturn, I suspect there's gas involved too. Maybe water vapor, or gas spinning off of Saturn. (Update from years later: yes there's an atmosphere to the rings, mostly ionized oxygen.) That would let the visible rings be much thinner than the transparent ones.

Here's the outer solar system, except with all the masses except the sun increased about 20x. That's enough to make the planets interfere with one another in a reasonable period of time. You can drag with the mouse to move the camera.
Here's the outer solar system again, except with all the masses except the sun increased about 20x, plus I reversed the direction of Uranus. This is a test of how stable it is for one planet to be going the opposite direction of the others, a question posed by Nick Hoffman.

Huh. That's the opposite of what I would have predicted.

How do stars travel in a globular cluster? Recall that there is no central black hole, and no significant overall spin.

Click here.

Do stars in a globular cluster interact strongly with each other, or do they just orbit the overall center of mass unhindered? Do they go in ellipses around the center of mass, or do they oscillate through the center?

Click here.


Source code for this gravity simulator
Scale model of the solar system
Lagrangian points and Klemperer Rosettes
Table of contents