Runge Kutta 4 For cloth simulation

Started by
12 comments, last by Shadx 18 years, 3 months ago
Quote:Original post by Shadx
Sorry about not being more specific. rk1 = hf(x,yi) rk2 = hf(x+dt, yi + rk1/2) etc. At one point I had my simulation working in such a way that I would do:


This is not quite correct! It must be
rk1 = hf(x     , yi        )rk2 = hf(x+dt/2, yi + rk1/2)rk3 = hf(x+dt/2, yi + rk2/2)rk4 = hf(x+dt  , yi + rk3  )yi = yi + (rk1+2*(rk2+rk3)+rk4)/6

I assume that the function hf multiplies with dt, otherwise rk1-rk4 must be multiplied with dt afterwards, i.e.
rk1 = dt * hf(x, yi)

and so on. Maybe this is the reason for the errors.

Lutz
Advertisement
Quote:Original post by Lutz

This is not quite correct! It must be
rk1 = hf(x     , yi        )rk2 = hf(x+dt/2, yi + rk1/2)rk3 = hf(x+dt/2, yi + rk2/2)rk4 = hf(x+dt  , yi + rk3  )yi = yi + (rk1+2*(rk2+rk3)+rk4)/6

I assume that the function hf multiplies with dt, otherwise rk1-rk4 must be multiplied with dt afterwards, i.e.
rk1 = dt * hf(x, yi)

and so on. Maybe this is the reason for the errors.

Lutz


hehe, no, I wish it was that simple. I was just showing what I meant by rk and forgot to put in a half time step for my k2 function. My RK4 implementation seems to be alright, for how it applies to individual point mass anyway.

For cloth simulation, I tried it with implementing the RK4 by calculating the force once and then applying the integrator or calculating the the force between every step of the integrator, and neither gave me good result. I will try putting in verlet instead in my next coding session.

Btw, h normally is dt...I also had explained that wrong...should be hf(t+h/2,y+rk1/2)

Thanks though,

Shadx
As was said earlier, if you don't reevaluate your force function between integration steps (in something like RK4 or Midpoint, etc) you are defeating the purpose of that integration system and it is a waste of time.

Think about it this way with Euler steps for clarity:

Straight forward Euler:
Calc Force
Integrate pos and vel with step = 1.0

If you were wanting a better fit, you might want two evaluations like with a midpoint style method (or just smaller Euler steps):
Calc Force
Integrate pos and vel with step = 0.5
Calc Force
Integrate pos and vel with step = 0.5

If you just do one force calc, it is the same as just taking the full single step with no benefit:
Calc Force
Integrate pos and vel with step = 0.5
Integrate pos and vel with step = 0.5 (second time is using the same force)

That all said, RK4 is probably overkill for your problem. It doesn't give you a lot more stability for stiff systems (like cloth) and has extra expense.

Beware about throwing around the Verlet thing. Verlet is just an integrator like Euler. In fact it is exactly equivalent to what many call semi-implicit Euler. No need to explain why unless you want to go into it. But the "velocity-less" Verlet that Jakobsen talks about in his paper is just an Euler method.

The trick of that paper that everyone loves really not the integrator it is the constraint solving through projection which has nothing to do with the integrator. This is where you just move the points to satisfy rigid constraints. But for cloth you may want rigid links but probably want some stretch just not as much as you get with springs that work in Euler methods.

So the solution (first proposed by Provot a while back) is to use springs with pretty stiff constants that give you good response but don't blow up. Figure out what you want your max over/under stretch to be. Then use projection methods to keep that stretch limit. So if your limit is 10% stretch, project to those limits if the springs go beyond them.

Works great. You get cloth that has some stretch but doesn't look like elastic. Plus it behaves in a more uniform manner in a way that straight projection doesn't.

For simulating more realistic cloth with actual stiff stretch properties, Implicit methods are probably the only solution. But to just get the look, I think Provot had it right.

Jeff,

I went back to my code and changed it so that I recalculate the the forces between each step. I must have done something wrong the first time I tried this approach because it works well now. I can now use a time step of 0.01 with a spring constant of 5000, which works well enough for the simulation I'm doing. Again, thanks for the help on this.

I have started looking at the paper that ury posted and I'm finding it quite interesting. I should have been clear about my goal from the begining instead of blindly trying to use RK4 for something that it's ill equiped to achieve. So before going forward, I'll try finding a solution that scales well enough to the problem at hand.

For those interested, I'm currently looking at the following paper "Interactive animation of structured deformable objects" and it's looking really promissing.

Quote:So if your limit is 10% stretch, project to those limits if the springs go beyond them.


I'm currently applying constraints based on a maximum possible stretched, because it's rather expensive, I only do it at the end of the rk4 integration instead of doing it between each step.

I also have collision and response done between spheres and AABB, but I've got some work to do since when it gets into constant contact, my point mass can sometime "wiggle" its way through the bounding volume :) At this point, I use collision detection and responsed based on the indivual point mass, without taking into account that those point mass forms a cloth. Same thing for calculating drag force. I need to change all this. At least I'm having fun!

Regards,

Shadx

This topic is closed to new replies.

Advertisement