View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Help on spring physics

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

12 replies to this topic

### #1bardok14324  Members

Posted 10 May 2012 - 10:28 AM

Hello,
I'm working with soft bodies using a physics engine. The soft bodies are simulated as tetrahedrons. My purpose is to unite 2 soft bodies that were once whole in the original mesh. In the simulator they are each a different entity . I thought that I should use spring physics to unite them. I used the following formula to unite the particles:

F = -kx -bv

where x is the difference between the 2 points that are attached by a string and v the difference of velocity between the two. My problem is that for a small k when I pull a softbody the other tends to follow slow, on the other hand if I increase the constant too much the two soft bodies move on their own but they stay attached correctly. I haven't been able to find a good value for a compromise. If someone can help me either with a new direction perhaps a different kind of force or another solution I would be very thank-full.

### #2sjhalayka  Members

Posted 10 May 2012 - 12:04 PM

Hello,
I'm working with soft bodies using a physics engine. The soft bodies are simulated as tetrahedrons. My purpose is to unite 2 soft bodies that were once whole in the original mesh. In the simulator they are each a different entity . I thought that I should use spring physics to unite them. I used the following formula to unite the particles:

F = -kx -bv

where x is the difference between the 2 points that are attached by a string and v the difference of velocity between the two. My problem is that for a small k when I pull a softbody the other tends to follow slow, on the other hand if I increase the constant too much the two soft bodies move on their own but they stay attached correctly. I haven't been able to find a good value for a compromise. If someone can help me either with a new direction perhaps a different kind of force or another solution I would be very thank-full.

OK, since this is a zero-reply thread that has been sitting idle for a while...

I think you're saying that x is the distance between particles? That would lead to a zero / vanishing -kx term only when they were at the exact same position, which seems odd, so I'm not sure if I'm interpreting you correctly.

Have you tried setting x to be something like the difference of the particle distance and the ideal, equilibrium distance (ie. x = distance - ideal)? I mean, if the distance between the two particles were equal to the ideal distance (which would be something non-zero, obviously, since you're trying to work with tetrahedra of non-zero volume), then the -kx term would be zero / vanish as desired? I could be wrong, but I thought it was worth a try.

Edited by taby, 10 May 2012 - 12:11 PM.

### #3bardok14324  Members

Posted 10 May 2012 - 01:34 PM

Excuse me for the incomplete description. Yes x is the distance between particle positions , the complete formula should have been
F = -k(|x|-d)(x/|x|) - bv
where d should be the rest length. I don't know why using this formula makes both soft bodies move on their own(for a big k)

### #4h4tt3n  Members

Posted 10 May 2012 - 02:29 PM

Excuse me for the incomplete description. Yes x is the distance between particle positions , the complete formula should have been
F = -k(|x|-d)(x/|x|) - bv
where d should be the rest length. I don't know why using this formula makes both soft bodies move on their own(for a big k)

What exactly do you mean by "move on their own"? Does the entire body move around in different directions? If yes, then there's a conservation of energy / momentum error. How exactly do you calculate v? The correct value is the dot product of the difference in velocity vector and the unit vector, v = (v2 - v1) . (x / |x| ), ie. the velocity vector projected onto the distance vector. Otherwise you'll add energy to the system.

I've made quite a few soft body simulations, and I won't mind digging out a few code samples for you.

Cheers,
Mike

Edited by h4tt3n, 10 May 2012 - 02:31 PM.

### #5bardok14324  Members

Posted 10 May 2012 - 10:53 PM

Thank-you for your help. Instead of explaining (as I'm bad with description) I recorded it for showing.

The velocity of the particles is given to me by the simulator. But I don't understand something now, if v is the dot product then the term bv is a number. Do I substract that value from all components or only from the .x component?

### #6h4tt3n  Members

Posted 10 May 2012 - 11:58 PM

The complete equation looks like this:

x = x2 - x1
v = v2 - v1
n = x / |x|
F = -[ k*(|x|-d) + b*(v.n) ] * n

In other words, the force vector is equal to the sum of the scalar spring force and damping force multiplied by the normalized distance vector.

Edited by h4tt3n, 11 May 2012 - 01:35 AM.

### #7bardok14324  Members

Posted 11 May 2012 - 01:43 AM

Thanks for clarifying that. I did as you told me but the problem persists. I tried introducing a damping force like this one

f = -kd v1 where v1 is the velocityof the particle in question when computing the forces acting upon it ( I hope I phrased it right)

The effect was that the unusual movement was considerably reduced but still persists and seems to be constant no matter how much I raise kd . I was thinking if I should add an angular damping force also, but I can't find a formula to make some sense of. Could you please tell of a formula for an angular damping force?

### #8h4tt3n  Members

Posted 11 May 2012 - 06:33 PM

My advise would be to NOT add any new features such as angular damping before you've fixed this bug. How do you integrate force with time, ie. how do you get from force to velocity and position? THe error might hide here. Do you calculate force, acceleration, and new velocity and position for eaach particle before calculating force and so on for the next particle? If so, then this is wrong - calculate forces for all particles first, then all acceleration and so on. I've seen this behaiour from not doing so.

### #9bardok14324  Members

Posted 14 May 2012 - 12:27 AM

My advise would be to NOT add any new features such as angular damping before you've fixed this bug. How do you integrate force with time, ie. how do you get from force to velocity and position? THe error might hide here. Do you calculate force, acceleration, and new velocity and position for eaach particle before calculating force and so on for the next particle? If so, then this is wrong - calculate forces for all particles first, then all acceleration and so on. I've seen this behaiour from not doing so.

The physics engine does all the work, I interact with the soft bodies by just applying force through the interfaces it provides me. The forces are calculated for all the particles which are tied by such springs and are added before the simulation step is taken ( a call to a function simulate(time_step)). Other than through forces it allows me to set/get the each particle's velocity and position.

### #10h4tt3n  Members

Posted 15 May 2012 - 05:59 AM

What happens if you do the following: Create a soft body of only two particles connected by one spring. Turn off all external forces such as gravity, air friction, and user interaction. If spring length = rest length, then absolutely nothing should happen. If spring length <> rest length, then the particles should oscillate for a while and come to rest. What happens?

Edited by h4tt3n, 15 May 2012 - 06:00 AM.

### #11bardok14324  Members

Posted 17 May 2012 - 11:40 AM

I checked it , it happened the way you said it would. I also tried to tie the particles using some form of spring joints from the engine with a little work around, and it had the same effect ( tendency to move in one direction). I'm beginning to believe that it could be due to the fact that the springs are made uneven ( n particles tied to m particles and no spring between the n or the m particles for stability).

### #12h4tt3n  Members

Posted 17 May 2012 - 01:42 PM

I checked it , it happened the way you said it would.

Ok, so far so good.

I also tried to tie the particles using some form of spring joints from the engine with a little work around, and it had the same effect ( tendency to move in one direction).

What is this engine, you are using? What little workaround? It seems the problem is somewhere inside this "black box".

I'm beginning to believe that it could be due to the fact that the springs are made uneven ( n particles tied to m particles and no spring between the n or the m particles for stability).

If all the physics is set up right, then this should not be a problem. It seems like you are violating Newton's laws of motion. Does all particles have the same mass? Is your engine based on force or impulse?

I would strongly recommend you to code all physics yourself and not rely on ready-made physics engines. If you don't know exactly how they work, debugging can be near-impossible as in this case. And again; I'd gladly share some code samples showing exactly how to make soft bodies without relying on external libs and engines.

Cheers,
Mike

Edited by h4tt3n, 17 May 2012 - 01:44 PM.

### #13bardok14324  Members

Posted 23 May 2012 - 11:42 PM

I'm sorry for the late reply

What is this engine, you are using?

It's physX 2.8.1 ( because it still has soft bodies).

I would strongly recommend you to code all physics yourself and not rely on ready-made physics engines.

I would if I could understand it all, but sadly at this time it's too late for me to do that. however I would really appreciate it if you could offer some samples on soft bodies. Perhaps I will find my mistake by understanding it .
Thank-you for your helpful posts, it helped solve a couple of my problems.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.