It has come to the point in my computing program now where I have 5 swinging pendulums that are all modified at once by slider values. These values are drawn onto the from and passed through the class pendulum. To change the values the update button is run, and their is a default option to use a setup that works. The values are also shown on screen through some simple labels. The zero button sets all values (except length) to zero.

The values for each pendulum drawn is:

- String length
- angle
- Acceleration (angular)
- Angluar velocity
- Damping or friction
- Gravity

My calcuations for these values: (Bob = the weight at the end of the string, and there are X and Y Co-ordiantes for it.

```
bobX = originX + (Math.Sin(angle) * length);
bobY = originY +(Math.Cos(angle) * length);
```

Caclulate Acceleration:

```
Angular Acceleration = (-1 * gravity / length) * Math.Sin(angle);
```

Increment Velocity:

```
Angular Velocity += Angluar Acceleration;
```

Increment Angle

```
angle += AngularVelocity;
```

Friction action, pendulum eventually 0's

```
AngularVelocity*= damping;
```

Now my next task is to make the pendulums collide "realistically" and recreate a newtons cradle type effect. I've looked into elastic collision solutions on particle e.g. here is an excellent example: https://stackoverflow.com/questions/345838/ball-to-ball-collision-detection-and-handling

I've also looked at the raw physics behind it here but my brain couldn't get to grips with the raw physics side of things.

So I'm wondering if anybody could help me figuring out the theory for the collisions.

My current idea is when the co-ordinates meet the velocity will simply change polarity e.g. +10 to -10 in the opposing pendulum. Am I correct here?

If you are into code I've posted the code on stack overflow here!

## Best Answer

There is something called impulse $J$ which represents a very high force over a short period of time resulting in a step change in velocity.

For a particle object $\Delta v = \frac{J}{m}$. When two objects collide and equal and opposite impulse acts on both of them resulting in

$$\begin{aligned} \Delta v_1 &= \frac{J}{m_1} & \Delta v_2 & = \frac{-J}{m_2} \end{aligned} $$

So how do you find what the impulse $J$ is and hence the changes in speed?

Typically a rule is placed for collision saying that the final relative velocity is proportional in magnitude to the initial relative velocity, but in an opposite direction. Namely:

$$ \left( \left( v_1 + \Delta v_1 \right) - \left( v_2 + \Delta v_2 \right) \right) = -\epsilon \left( v_1 - v_2 \right) $$

This only applies for the components of velocity along the contact normal direction (along the impulse direction). The constant $\epsilon$ is called the coefficient of restitution and it is $\epsilon=0$ for a plastic contact (sticking) and $\epsilon=1$ for an elastic contact (bouncing) and everything in-between.

Combine the above to get

$$ \boxed{ J = (\epsilon+1) \left(v_2-v_1\right) \left( \frac{1}{m_1}+\frac{1}{m_2}\right)^{-1}}$$