physics – Why is my spring exploding? And tips on how to repair it?

physics – Why is my spring exploding? And tips on how to repair it?

[ad_1]

To illustrate I’ve a 1-dimensional spring, and I need to simulate it by making use of a drive which will differ with time. We are able to skip friction and dampeners for now.

From what I realized a few years in the past in highschool physics, one can apply Hooke’s regulation and calculate the ensuing drive, which will be utilized to calculate the ensuing displacement.

This is a trivial snippet that in precept does simply that:

float spring = stiffness * displacement;
float totalForce = drive - spring;
displacement += (velocity * deltaTime) + (totalForce * deltaTime * deltaTime / 2.0f);
velocity += totalForce * deltaTime;

I am over simplifying some issues, just like the mass of the spring, and that is by design. I might slightly have a easy system than a fancy one that’s completely bodily correct.

With a non-zero preliminary displacement, and nil drive, this could oscillate in place. Nevertheless, after I truly go and simulate it, the oscillation magnitude grows and grows infinitely.

I attempted plotting this, and that is the consequence:

Oscillation exploding

I am studying some stuff on-line, and it looks as if this methodology is notorious for being unstable, though it is probably not clear to me why.

I will proceed researching, however is there a method to repair my methodology so it is extra secure, or alternatively, is there a identified easy, secure methodology to simulate one thing that appears like a spring? As soon as once more, simplicity is extra essential than good accuracy.

[ad_2]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply