# How To Correctly Caluclate Compression Speed For Damping?

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

## Recommended Posts

Hello!

So far I've been doing this:

v = (x - x0) / dt

To determine the compression speed used for damping in spring's equation(

F = x * k + v * c

).

v = compression speed

x = compression

x0 = last frame compression

k = stiffness

c = damping

However, I know that this method is not quite correct and mostly results in critically unstable results. I'm wondering how to calculate it correctly for

• 2 mass connected by a spring case
• a mass connected to a spring which is connected to a static point

And hints and help appreciated :)

##### Share on other sites

Not sure of what you're asking. Do you mean determining the point mass velocity at a future time knowing the spring ODE and the initial state?

Springs were covered in this talk with a semi-implicit Euler solution for this ODE as well.

##### Share on other sites

I would think the relative velocity along the spring axis.

##### Share on other sites
As Dirk pointed out, looks like v is the difference between the two masses velocities along the spring axis. Example:

n = (b - a) / |b - a|

v = dot(v_b - v_a, n)

And, more generally,

F_a = - (c * v + k * (|b - a| - r)) * n
F_b = - F_a

Where a and b are the positions of the two masses, v_a and v_b their velocities, and r the spring rest lenght.

##### Share on other sites
Also, you might want to consider store v_i as a state and use the semi-implicit Euler integrator which is stable even for undamped systems (k_c = 0).

##### Share on other sites

Hi! Thank you very much. This seems to be exactly what I need. I'm glad that I asked it here:)

##### Share on other sites

Also, you might want to consider store v_i as a state and use the semi-implicit Euler integrator which is stable even for undamped systems (k_c = 0).

I always use symplecit Euler. I thought that I used explicit one, but than I found out that explicit Euler uses last frame velocity to integrate position and only than integrates velocity which doesn't make sense for me. I always integrate velocity first and than use it. However, it's easy to set the stiffness high enaugh to blow symplecit Euler. I also found it being ultra easy to blow RK4. I haven't yet tried verlet. I also haven't found out how it is possible to implement implicit Euler in game. And lastly - I gotta try out PBD as it seems to be the best stability and performance balance yet made for stiff spring system. ;)

Also it seems that previously I calculated the spring velocity implicitly, but in unsuitable case?

##### Share on other sites

Indeed deriving spring forces from energy gradients and adding damping forces into the equation is horrible if you have a linear integrator.

Erin Catto talks about a bunch of integration stuff in the slide I've posted and also about spring joints (or soft constraints if you will) which are a possible replacement for springs and fit very nicely inside a particle/rigid body solver.

Yes, you've approximated velocity to first-order.

I personally haven't take the time to implement implicit Euler but it shouldn't be to hard to do so using the Newton-Raphson method for solving a system of non-linear equations because the next position is defined implicitly in terms of the next velocity.

Currently most game physics engines use PBD for cloth/particles and VBD for rigid bodies. Therefore implementing this would be usefull for comparison between solvers.

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633662
• Total Posts
3013231
×