Jump to content
• Advertisement

# Help on spring physics

This topic is 2397 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

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.

#### Share this post

##### Share on other sites
Advertisement

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

#### Share this post

##### Share on other sites
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)

#### Share this post

##### Share on other sites

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 = (v[sub]2[/sub] - v[sub]1[/sub]) . (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

#### Share this post

##### Share on other sites
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?

#### Share this post

##### Share on other sites
The complete equation looks like this:

x = x[sub]2[/sub] - x[sub]1[/sub]
v = v[sub]2[/sub] - v[sub]1[/sub]
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

#### Share this post

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

f = -k[sub]d[/sub] 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 k[sub]d[/sub] . 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?

#### Share this post

##### Share on other sites
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.

#### Share this post

##### Share on other sites

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.

#### Share this post

##### Share on other sites
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

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5
• Advertisement

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633734
• Total Posts
3013587
×

## 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!