Gravity Simulator
=================

by JJF


This program seemed like a nice idea in the beginning. Write an ARM code
gravity simulator and sell it to Acorn User for a vast sum of cash. However,
the program didn't work quite as I'd anticipated, and I ended up with
something I am nervous about even sending to a PD library, let alone a
magazine.

The program uses Newton's Law of Gravitation to discover the force which is
exerted on each object. Basically, for those unfamiliar with this, the law
states that :

  F = G M m / (r^2)

Where F is the force between two objects, M and m are their masses, and r is
the distance between them, whilst G is some constant. Then, Newton's Second
Law (F=ma) is applied to this equation, leaving us with :

  a = G M / (r^2)

Where a is the acceleration that is caused on an object by a second object
of mass M. This acceleration is resolved in horizontal and vertical
directions, and, after all the forces exerted on the object are considered,
the components of the accalerations are added up and added onto the velocity
of the object. Then the next object is considered in the same manner.

The first problem is that the force between two objects on different sides
of the screen is miniscule; in fact, since it is held 'scaled up' by a
massive factor (since the ARM chip cannot handle fractions), it is far too
small to register unless G is very large. However, when G is very large,
the forces experienced when two objects are close are phenomenal - far too
large, in fact, and the objects suddenly go streaking off into the sunset.

The second problem is that the gravity simulation is 
The other problem I encountered was that the animation is mysteriously 
very jerky. I have since succeeded in fixing this, however...

There are three variables defined early in the !RunImage file that you might
like to alter. The first, bouncedamp, is a number by which the velocity of
an object colliding with the side of the screen is 'damped' - it is mainly
just to prevent velocities from becoming too high. The second, sqrdamp, is
provided to 'damp' the gravitational force between objects that are close
together. Basically, an object has a uniform gravitational field up to a
distance of sqrdamp from it, with Newton's Law of Gravitation applying at
distances above this. The final variable, G, controls the strength of the
gravitational forces. The higher the value of G, the more particles attract.

Feel free to muck about with the program to your heart's content. It is
entirely PD, so, if you think that you can improve it, then feel free. I
might feel a bit hurt if you try to pass it off as all your own work,
though...
