RE: https://mastodon.gamedev.place/@runevision/115736639369756581

What are good approaches to enforce minimum distances in a simulated web of “springs”?

I have forces that both push and pull to approach an ideal distance between nodes, but avoiding too short distances should take priority over avoiding too long ones. If I just make the pull forces weaker, things converge slower, which is not great.

@runevision Maybe an asymmetric spring-damper? Change your force constants if the distance is less than a "too close" distance.

Something like f = d < d_min ? (k_min * (d_min - d) - c_min * min(v,0)) : (k_max * (d - d_max) - c_max * max(v, 0))

Obviously this can become a stiff spring that will blow up your integrator so choose a large k_min wisely, or improve the integrator.

You could also make the <d_min spring exponential for possibly better animation.

@Donzanoid @runevision I would be careful of discontinuous changes, at least in real physics these can lead to some highly nonlinear behaviour.

Perhaps have an asymmetric cubic force curve?

@dougbinks @runevision

Good point. It's C0 continuous but not C1.

Conflictingly, that's fine for old explicit integrators that break down under high stiffness. But not ideal for implicit integrators that handle high stiffness well.

We deal with asymmetry all the time in explicit integrators (e.g. Coulomb friction, which isn't even C0) by managing time steps, force magnitudes and integrator type.

A solution to make it C1 if there is trouble is add a quadratic smooth on the boundary.