## Circles!

### 10/2013

I've been working on a simulation in javascript. It's a bit of fun.

Add circles by clicking or give new circles velocity by clicking and dragging.

The rules are quite simple:

• The circles are attracted to each other at long ranges by an 1/r2 force similar to gravity.
• At close ranges (when they touch) there is another 1/r2 repulsive force so that they 'bounce' off each other.
• While circles are touching each other the forces are scaled by 0.99, this has the effect of sticking them together. This is sort of a binding energy term.
• There is a drag term that creates a force that is proportional to the velocity squared in the direction opposite to velocity. This is similar to air-resistance.

Note, in the version above the maximum number of circles is limited to 48, old circles pop out of existence as newer ones are created. This is so that it does not slow down on mobiles and it means that you can clear the field to start again without too much hassle.

The circles stick to each other into a close-pack hex pattern. The circle in the middle has six lots of the sticking factor (0.996) on it. The formation of blobs in the first few stages are quite predictable:

These circles are the only, and the simplest, way of attaching circles together. This is also the only energy minimum for the circles. This becomes increasingly not true as the number of circles increase.

For example with 6 circles, here are two ways they can be combined: (There are actually 3 ways as you will see later.)

The number of ways that the circles can be combined as the number of circles increases. However here are the just a few of the most common modes:

To explore the energy levels of the systems I created a modified version that on each frame of the animation runs a complete simulation until it has 'settled down', that is, when the average velocity is below a chosen value. On each of those frames the circles are moved to the middle (so that you can see them easily) and the sum of the distances between each object is drawn on screen as a dot. The dots make up a graph that has frame number on the x-axis and sum-of-r on the y-axis. I'm relating the sum-of-r to be a simple metric of the energy of the cluster (However I think that sqrt(sum(r2)) is a better one). After a few frames an energy band graph is drawn. After a certain number of frames the number of circles in increased. Note that the initial position for each circle at the beginning of each simulation is random inside of a big enough square.

You can try it out for yourself.

If you don't want to wait for that to run, as it does take a while, below are the results for the first 600 simulations: The first few energy levels drawn out. Click for larger version.

The first energy levels are not split and form solid bands, but with 6 circles there are three different combinations that are stable, each with a different energy level. You can also tell that the lowest energy level is the most common (the line is denser) followed by the highest energy state. The middle state is the rarest.

Letting the simulation run for much longer (it slows down considerable with more circles) I've some evidence of the different energy levels of up to 11 circles. The graphing is done with a modulo of the screen height, so as it appears that the 8 circles have less energy than 7 it is actually off the top of the picture and rolls back onto the bottom again. I've drawn on what I think are the levels. With some indication of how common they are. Energy levels with the levels marked on. Click for larger version (recommended).

This is where I'll call and end to my project for now. I think that it is interesiting to see that with only the implementation of some basic (in this case crude also) physics rules more complex systems develop.

Other things to try:

• Observe spherical harmonics (sent the repulsion force low to act like a compressible liquid)
• Test the easy scattering angles (fire high velocity circles into a fixed lattice of circles)
• Do a histogram of the energy levels
• Find energy levels branching probabilities

A friend of mine who wanted no cap on the number of circles: here it is.

The source code for the simulations is open, just right-click and choose view source. It is fun to play with the parameters just keep the (c) MJS 2013 at the bottom.