Linear and angular damping implementation in b2Island::Solve

Hi,

I find that for damping values > 1.0f, velocity values are dependent on time step.
After going through the damping implementation details, I found that following scheme works independent of time step and unconditionally stable (implicit scheme).

// Applying force and damping
// ODE: m * dv/dt = F - c * v
// using Implicit difference scheme : m * (v(t+dt)-v(t))/dt = F - c * v(t+dt)
// Rearranging: (1 + c/m*dt)*v(t+dt) = (F/m*dt + v(t))
// v(t+dt) = (v(t) + F/m*dt) / (1 + c/m*dt)

v.x = (v.x + h * (b.m_gravityScale * gravity.x + b.m_invMass * b.m_force.x))/(1 + b.m_linearDamping * h);
v.y = (v.y + h * (b.m_gravityScale * gravity.y + b.m_invMass * b.m_force.y))/(1 + b.m_linearDamping * h);
w = (w + h * b.m_invI * b.m_torque)/(1 + b.m_angularDamping*h);

Please give your inputs, whether this implementation is ok?

Thanks
Rajesh
If the forces and gravity are zero you have:

Code:
v1 = (1/(1 + h * d)) * v0


Now take two time steps of h/2:

Code:
v1a = (1/(1 + h * d /2)) * v0
v1 = (1/(1 + h * d / 2)) * v1a = (1/(1 + h * d / 2))^2 * v0


So the assertion is:
Code:
1/(1 + h * d) == 1/(1 + h * d / 2)^2
1 + h * d + (h*d/2)^2 == 1 + h * d
(h*d/2)^2 == 0


This is a good approximation for small time steps.
Thanks Erin

Original thread: https://box2d.org/forum/viewtopic.php?t=8829