[Q] ElastoLab Physics
David Buck
david at simberon.com
Tue Oct 14 08:09:20 UTC 2003
>
>
>Hello!
>
>Have anyone figured out how to use the ElastoLab physics package? I would
>like to try it with a simulator I am working on but can't figure out how to
>set things up. Is there any good examples for this somewhere?
>
As Karl said check out the testcases in the class
SimulatedPhysicsTestcases for examples.
>Do particles collide?
>Can you have objects other than round particles? For example a simple
>square as a physical object?
>
>Thanks! Johannes.
>
<the short answer>
No, no, and no.
<the long answer>
Particles don't collide because the math gets too hard. Physics is easy
to solve when the functions are smooth and continuous and there are no
sudden changes. With springs and elastics, you can step forward at 0.1
second intervals and accurately predict where the particle is going to
be. With collisions, you (in theory) have to reduce your step size
suddenly to 100 microseconds or smaller to figure out how the collision
occurs. After the collision, you would have to return the step size to
something bigger in order to calculate quickly enough.
Physics simulators don't try to reduce the step size just to simulate a
collision. They determine the time of the collision, add an impulse (a
force that takes place instantly) and add the impulse to the particle to
make it change direction and velocity. Determining the time of the
collision is hard - it can only be done by guessing when the collision
might take place, stepping the simulation by that time, and checking to
see if you're close enough. This boils down to the "zeros of equations"
problem with two catches - 1) you want the first zero, not any one and
2) you want the zero of a minimum of multiple other functions (the
distances of each particle from each barrier). ElastoLab does this by a
bisection algorithm. Better algorithms would help.
A collision, though, is an easy problem compared to resting contact.
Consider a particle sitting on the floor. What is the time of the next
collision? Zero. You can't step forward by zero seconds, apply an
impulse, and repeat. You'd think you could just stop the particle.
This doesn't work either. A particle rolling down an inclined plane can
still move - it just can't move into the plane. It still has gravity
pulling it down and possibly springs trying to push it into the plane.
The force you apply to the particle to keep it from penetrating the
plane can only be calculated by computing the total forces ignoring the
plane, then by calculating a force normal to the plane that's just
strong enough to prevent inter-penetration. This is called dynamic
constraints.
Dynamic constraints work well when there is only one constraint. If a
particle is sitting in a V-shaped valley, it is touching two barriers at
the same time. Solving for one barrier creates forces that push it into
the other. Your particle will wiggle back and forth and eventually fall
through. You have to solve for all constraints simultaneously by
solving something called an LCP problem (lookup an article by Baraff in
SIGGRAPH 1984 called "Fast Contact Force Computation for Nonpenetrating
Rigid Bodies"). The algorithm for solving this involves solving a
system of linear equations inside a double or triple nested loop. The
ElastoLab physics engine does all this.
Now, suppose you have particle-particle collisions. You can now create
a V-shaped valley and drop hundreds of particles into it. If you want
the particle collisions to be rigid and not squishy, you have hundreds
of simultaneous contact points that can quickly change. In theory, the
algorithm can handle it, but your performance drops so dramatically that
it can no longer be calculated in real-time or anything close.
Round particles have the advantage that there are normally a finite
number of contact points of zero size. A brick sitting on the floor has
an infinite number of contact points. You now have to choose which
contact points you are interested in simulating. For example, a brick
sitting on table (2D) has two contact points. A brick falling off the
edge of a table has one contact point. The problem is that as the brick
falls, the contact point on the brick changes.
Since ElastoLab supports Baraff 1984, it should be possible to handle
particle-particle collisions and non-sphere particles. Supporting this
algorithm is one of the last things I did in ElastoLab and I never had
the energy to extend it to those areas.
Bottom line - simulated physics is hard.
David Buck
Simberon Inc.
www.simberon.com
More information about the Squeak-dev
mailing list
|