Spring simultation problem!!


I’ve just made a simple spring simulation but i’ve a problem .
I make two particles and i join them by a spring. Suppose the normal length of the spring is 1.0 and the distance between the partcles is 1.5. One of the particle has a 1/Mass = 0.0, non force has effect on it. If i run the simulation the spring must swing around. In my simulation, the spring swings around but the distance between the particle never stop increasing. So where is the problem? If someone can help me, please i don’t understand what is the problem.


Your simulation is probably not accurate enough which causes errors to build up and the energy of the system to increase (until it all explodes).

Try lowering your timestep or try a better numerical integrator like the 2nd or 4th order Runge-Kutta integrator. Look at Numerical recipies (www.nr.com).

… simple harmonic motion?

Take a look at http://www.cs.cmu.edu/~baraff/pbm/particles.pdf

On page C7 is a description of a binary force using Hooke’s law “of springs”. The equation has a force term based on the spring’s offset from its rest length. The offset is measured at one of the ends assuming the other end is fixed. You’ll notice importantly that it also has a term based on the velocity of this reference point. It is a dampening term. Cars use shock absorbers along with springs to decay harmonic oscillation quickly.


Otherwise a simple Euler step integration will blow up unless the time step is ridiculously small. It is always a good idea to use a better integrator such as a 4 step Runge-Kutta. (There are much more robust integrators for “stiff” systems. Stiff refers to the min and max eigenvalues of the system of DiffEq’s. If they’re vastly different, say max/min > 1000, the system needs small ridiculously small time-steps to solve both the fast and slow moving items of the system.) The material on the CMU web site http://www.cs.cmu.edu/~baraff/pbm/pbm.html is well done.

Hello !

you are interested in ressort ? I tried to realise a model for a car, you can see some of the results at www.multimania.com/screamers/physique (in french sorry) if you wish i can send you an application running…

Just to tell you that at the beginning I got your problem.

I Imagine that your are using some intergrator like:

a = acceleration
s = speed
x = current position
t is time

now if the acceleration was gravity, you should have a = g
and then s = gt (first integration)
and x = 0.5 gt² (second one)

and if you write the code, you will have a loop with this in it :

a = new acceleration // gracity or ressort formulas
s = s + a
x = s + x

Display x

NOW YOUR PROBLEM APPEARS IF you add somewhere an if. Let’s say that if x==0 then you have a choc with the ground, in reality you should change the acceleration, but if you do that, you may colide. So you interract directly with s. And here is the problem. By doing this you may take in consideration that what you are doing is physicly wrong… Well. I’am seeking… but you see ? the problem is after an if.

try using damping… as say the post before.

Tell me what happend with your project. screamers@multimania.com I would be interested !