Rigid bodies and infinitely stiff springs ?

1. Sep 21, 2011

stasb

Hi, guys!
I've managed to implement a decent enough rigid body simulator for my 2D game using my sketchy high-school physics knowledge.
Now I'm trying to pin some rigid bodies together. Connecting them with springs doesn't quite do the job. Too soft, the bodies drift apart. Too stiff, the simulation explodes. The smaller the integration timestep, the stiffer the springs I can have. What happens to linear\angular positions and velocities of two rigid bodies connected by a spring when stiffness approaches infinity and the timestep is infinitely small? Can't figure it out for the life of me, but something tells me it's a cheap solution to the problem. Any insight highly appreciated.

2. Sep 21, 2011

Ken G

The stiffness is often expressed in terms of the ratio of the constant of proportionality between the force and the stretch of the spring, called k, and the inertia of the object m. The frequency of oscillations scales like the square root of k/m, so self-similar behavior should appear when the timestep is scaled with the square root of m/k. That might be considered the inverse square root of the stiffness. If k/m goes to infinity, then the timestep needs to be infinitely short. That might become computationally expensive! I would think you might want to set k/m at the smallest value that seems to keep the masses from drifting apart, then scale the timestep with the inverse square root of that to keep things from exploding. That should let you get the longest possible timestep. But I'm not sure why the masses drift apart-- springs are pretty good at keeping things together! So your answer might also depend on what it is that is making the pieces wander away-- it depends on whether they are given some characteristic speed by what you do to them, or some characteristic energy.

3. Sep 21, 2011

stasb

Hmm... I'll try to explain what I'm asking for.
If we have two point masses connected by a spring with an infinite stiffness, we can intuitively tell the net effect of the spring without doing an infinite number of infinitely small timesteps. The point masses would simply stick together. What happens if we have rigid bodies instead?

4. Sep 22, 2011

AlephZero

The rigid bodies "stick together" to form one larger rigid body.

The only difference from point masses is that if the bodies have a finite size, you will need to find the CG position of the combined body, and if your simulation includes rotation you will need the moments of inertia about the new CG.

When you know the motion of the CG of the combined body, you can find the position of the original parts by geometry. You don't need to know the forces between the parts of the combined body.

If finite sized bodies collide and stick together, you can model what happens in the collision in the same way as any other inelastic collision, using conservation of linear momentum and angular momentum. You don't need to find the forces explicitly.

5. Sep 22, 2011

Ken G

Yes, if you want rigid bodies, why mess with springs in the first place? Just apply the rigidity constraint manually by asserting the shape of the combined bodies, and use the extensive bulk of physics built up around rigid bodies. That generally separates the problem into what the COM is doing, which is just like a point mass, and what the internal rotation is doing, which requires the moment of inertia concept, as AlephZero said.

6. Sep 22, 2011

stasb

I think there's a misunderstanding going on... I need the two rigid bodies to be pinned together at a single point, allowing them to change orientation relatively to each other, not just lump together two rigid bodies and have them act like one. By the way, Ken, congratulations post #1337. :)

7. Sep 22, 2011

chrisbaird

You don't want springs in that case. You want joints.

8. Sep 22, 2011

stasb

Yes, I want joints. Simulated by infinitely stiff springs.
No, I don't want to be linked to articles explaining the "proper" way to do it. They're way over my head. The only one I can actually grasp (http://www.gamasutra.com/resource_guide/20030121/jacobson_02.shtml) talks about simulating jointed rigid bodies using particles and stick constraints.

It doesn't give a mathematical proof, but it's quite intuitive for particles.
I'm trying to derive an analogous solution for rigid bodies.

9. Sep 22, 2011

AlephZero

Apologies for misunderstanding the OP.

Unfortunately, from my own experience the only way that is likely to work correctly and efficiently IS the "proper way".

The basic cause of the problem is the relative rotation of the two parts that are pinned together. Unless you have a model that "knows" that the relative motion of the pinned parts in each time step is around the arc of a circle, not along a straight line, you will always get the problem that the spring is stretched or compressed to the wrong length at the end of the step, and therefore you will get unwanted oscillations of the structure or the simulation will "blow up" unless you take tiny steps

What you are trying to do is a hard problem. If it's any consolation, some of the world's "industry standard" finite element analysis packages also made a mess of trying to model this, back in the 1970s and 80s before the "proper way" was widely known.