# Chaos pendulum explanation

This image shows how I programmed my computer to get the simulation of the Chaos Pendulum behavior. See explanation below.

1. The following simplifications have been done in order to speed-up the calculations:

1 — The moving point is not attached to a pendulum: it simply moves on an horizontal table. So there are no height variations of the moving point while it runs.

2 — Some friction is needed, otherwise the moving point will never stop! I used a fluid friction that has the simplest law: the friction force is always proportional to the moving point speed.

The calculation is made step-by-step on a fixed slice-time basis dt. The variables needed are position and speed, both X and Y axis. On each step we do the following

1 — obtain the overall forces that apply to the moving point;

2 — assuming the mass value of the moving point is 1, the accelerations are the same numeric value of the forces;

3 — given the initial speed we get the final speed (which becomes the initial speed for the next dt time slice);

4 — given the speeds and dt we get the new moving point position. That is, we integrate the acceleration twice to get the speed and position variations of the moving point.

So start with the calculations! We must setup the coordinates: I put coordinates 0, 0 to the corner of the screen, and the table size to the screen resolution (so screen and point coordinates are the same).

The halfway of the screen size is the center of the circle were the attractors are placed. Given the radius of the circle we get each attractor position:

1 — Let the table size, both X and Y, is TS (Table Size), the circle radius is R and the attractors number is AN

2 — The coordinates of each Nth attractor are:
● AxN = TS ÷ 2 + R · cos( 2 · π · N / AN)
● AyN = TS ÷ 2 + R · sin( 2 · π · N / AN)

We need some more coefficients:

G — the attraction coefficient, we’ll use it to get the forces between the moving point and each attractor

FF — the fluid friction coefficient, that slows down the moving point movement

h — the distance between the attractors and the table

dt — the time-slice. Too short implies a lot of time to perform the calculus, too long can result in unpredictable results

G, FF and h must be chosen by chances as to obtain “beautiful” curves. I used G=25, FF=0.0015, h=50 and dt=0.25

For each run we must initialize the moving point position and speed:
● X and Y = starting position
● Sx and Sy t= 0 (initial speed).

For each dt time slice the following is needed:

Initialize the overall forces that apply to the moving point with the friction force. The friction force is proportional to the mass speed, hence
● Fx = - Sx · FF
● Fy = - Sy · FF

For each attractor (you will need a for-next loop):

Get the distance between the moving point and each attractor
● Dx = X - AxN
● Dy = Y - AyN

The distance between the moving point and the attractor is:
● D ² = Dx ² + Dy ² + h ²
● D = ( Dx ² + Dy ² + h ² ) ¹ˊ²

so the force is
● F = G / D ² = G / ( Dx ² + Dy ² + h ² )
but we need the forces in X and Y directions, which are:
● Fx = F · Dx / D
● Fy = F · Dy / D

All the indented text above is written for clarity. The fastest way to calculate the overall forces is using an intermediate value:
● Z = G / (D ² · D) = G / ( Dx ² + Dy ² + h ² ) ³ˊ²
● Fx = Fx + Z · Dx
● Fy = Fy + Z · Dy

Once we know the forces, we get the new speeds and position (remember the mass is 1, so forces and accelerations are the same numeric values):
● SxNew = Sx + Fx · dt
● SyNew = Sy + Fy · dt
● Xnew = X + ( SxNew + Sx ) · dt / 2
● Ynew = Y + ( SyNew + SY ) · dt / 2

The positions we get are the screen positions expressed in pixels, so it's easy to draw the curve on the screen. We need to repeat the step-by-step calculation until the moving point stops (*), and repeat all the process for each starting position you want.

(*) How to know when the moving point stops? Well, I did it in the program to shorten the calculationtime. But the safest way is to decide a fixed number of iterations. If this number is great enough there won’t be problems. To know which is the attractor that captured the moving point, look for the nearest attractor to the final position of the moving point.

2. What program did you use to set this up with? It's a great explanation!

3. Thanks! I programmed it from scratch, with powerbasic

4. Thanks for the quick response! Do you mind if I use some of the images (screenshots from your video) and parts of your description for a project I'm working on? (It's not commercial, just for school)

Thanks,
Matt

5. Can you make this program available for download please?

6. Ciao, sto facendo un progetto scolastico sui frattali e sto sviluppando un programma in C# simile a quello fatto da te ma, se puoi, avrei bisogno di qualche chiarimento:
non ho ben capito se in queste formule:
Fx = Fx + Z · Dx
Fy = Fy + Z · Dy
i secondi Fx e Fy indicano la forza di attrito giusto?
poi, le formule:
SxNew = Sx + Fx · dt
SyNew = Sy + Fy · dt
SxyNew si riferiscono alla nuova velocità del punto mobile no? allora perché ci sommo le Fxy di ogni attrattore?