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
- Acceleration (angular)
- Angluar velocity
- Damping or friction
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);
Angular Acceleration = (-1 * gravity / length) * Math.Sin(angle);
Angular Velocity += Angluar Acceleration;
angle += AngularVelocity;
Friction action, pendulum eventually 0's
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!