# Verlet integration and dampening

This topic is 662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Huh, I don't understand the policy of not reopening old threads if post is relevant to them...

Anyway, here is a thread (http://www.gamedev.net/topic/394985-verlet-integration-spring-system-question/) that I contributed to 10 yrs later (!).

The author shows this excerpt:

float dampFactor=0.9f;
node_curr->pos.x += (node_curr->pos.x - node_curr->LastPos.x) * dampFactor + node_curr->force.x *dt*dt;


So as you see velocity is simply multiplied by the velocity factor.

From what I know you should actually mul velocity by Pow(dampFactor, deltaTime). At least when it comes to Euler integration. Which is correct for Verlet integration? To be hones mul by just a single scalar does seem to have sense as in Verlet integration we also don't mul velocity by deltaTime hence why would we the damp factor?

So which is correct?

##### Share on other sites

Velocity isn't really present in verlet, and calculating that pseudo velocity on the fly is already an approximation, so linear damping like above should be just fine. Also I'm not sure where you got: v' = v * pow( c, dt ). I've wanted to do the derivation for damping on Euler for a while now, so here it goes (don't read if you don't care):

I was referencing thisthis and this to get the following:

So we start with our equation of velocity $$v$$ and acceleration $$\dot{v}$$ with a damping coefficient $$c$$:
1. $$\dot{v} + c * v = 0$$
2. $$\dot{v} = -c * v$$
3. $$\int{\frac{1}{v}}\,dv = \int{-c * v}\,dt$$
4. $$ln|v| = -c * t$$
5. $$v = e^{-c * t}$$

It looks like equation 1 is a first order linear homogenous equation, so I google this term and figure out (with the links above) how to get the ODE's solution, which is line 5. Not sure if I did the steps 3-4 100% correctly, but whatever

So now let me grab Erin Catto's notes from Box2D (link above):

// ODE: dv/dt + c * v = 0
// Solution: v(t) = v0 * exp(-c * t)
// Time step: v(t + dt) = v0 * exp(-c * (t + dt)) = v0 * exp(-c * t) * exp(-c * dt) = v * exp(-c * dt)
// v2 = exp(-c * dt) * v1
// v2 = v1 * 1 / (1 + c * dt)


So I suppose Catto didn't want to call the exp function a million times each game loop. This makes sense since it's expensive compared to float MUL operations, so he used a Pade approximation of the solution, which finally gives us:

$$v' = v * \frac{1}{1 + c * dt}$$

##### Share on other sites

In step 3 you have a 'v' too much on the right hand side. And obviously you derivation is wrong as you are missing the v0. In order to get this you need to add an integration constant  (in step 4) and then solve for v(0) = v0. I can provide a full derivation, but maybe you try yourself first.

Edited by Dirk Gregorius

##### Share on other sites

Looking at the old thread, you are both giving too much credit to a physically incorrect formula and overthinking the calculation.

• Since dt is constant, scaling velocity by k1=pow(k,dt) rather than by k2 is exactly the same thing; you are simply expressing your damping constant on a nonlinear scale, with a gratuitous calculation.
• The difference between current and previous position is the time step multiplied by the velocity of the previous step; scaling it is entirely appropriate if you want an exponential decrease of speed.
• On the other hand, common physical systems have a variety of "damping" forces with all kinds of laws. Velocity decreases exponentially only for an overdamped linear oscillator with no driving; using any estimate of speed to compute force properly is more general in theory and less error-prone in practice than taking this kind of shortcut.
Edited by LorenzoGatti

##### Share on other sites

This topic is 662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628676
• Total Posts
2984175

• 13
• 12
• 9
• 10
• 10