Jump to content
  • Advertisement
Sign in to follow this  

Verlet integration and dampening

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

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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 smile.png


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
// Pade approximation:
// 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 this post

Link to post
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 this post

Link to post
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 this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!