4 hours ago, Irlan Robson said:
Both approaches uses the Sequential Impulses techique developed by Erin Catto. More one this topic:
This is not using sequential impulses. It is using the naive impulse method.
The second looks like a derivative of Catto's resources.
5 hours ago, phenom120 said:
I'm currently implementing a 2D physics engine, then i stuck in collision resolution. So i did a search in google, and i found this passage, It explains how to use impulse to separate two objects.
But after that, i found another another passage, this article is very complicated, but they seem talking the same thing ——— how to implementing the collision resolution. So now, what i confuse is why are there two completely different approaches of collision resolution? What's the difference between them? Which approaches is right?
I am not a native english speakers, so i hope you can understand what i wrote.
Thanks.
Here is the eventual result of the first link you posted https://github.com/RandyGaul/ImpulseEngine
The second article is nearly the same thing, except a little more is added. They are using a more abstract mathematical strategy to derive the same exact equation. However, the more abstract strategy makes it clear how to extend the first approach with more features.
The main feature is to include impulse accumulation, caching, and clamping. This feature transforms the first article into a full-blown Gauss-Seidel solver, which can converge. This means you will get nice stacking behavior.
Also the abstract mathematical strategy can be used to derive more equations for different behaviors, and this is called "constraints", to simulate specific things like prismatic or revolute joints.
So how can you go from the first article's strategy (naive impulse method) to the second (constraint method)? You need a few things.
- Impulse accumulation
- Impulse clamping
- Impulse caching
You can do 1 and 2 simultaneously, but 3 will require additional work.
Here is some sample code for the naive impulse method in your first article. And here is some sample code for the sequential impulse method. After comparing them side by side it is easy to see a few key differences. Here is step 1 and step 2. The accumulation for step 1 is stored here. For every collision there is one arbiter. The arbiter persists between simulation ticks in order to implement step 1, and to do this step 3 is required. Step 3 is implemented by keeping the arbiter around from one simulation tick to the next. Here is where Arbiter lifetime is implemented.
This piece of the naive method is completely replaced by step 1 and 2. The naive method throws away negative impulses. However in practice negative impulses are extremely important for convergence and correct overshoot when solving multiple contacts simultaneously. Only the accumulated impulse needs to be clamped above 0 in order to ensure the constraint does no work (d'Alembert's princple), or in other words, projection onto the constraint plane.
This hack completely disappears from the naive solution.
The friction model changes, though is still based on Coloumb's law. In your second link friction is modeled with a constraint almost entirely the same as the contact (collision) constraint.
And finally, this piece here is replaced by Baumgarte stabilization. Baumgarte is just an additive term, that was pre-calculated up here. There isn't much to Baumgarte since it's so simple. You calculate the position error of the constraint, and then take a small factor of it (like 0.2) and feed that directly into the velocity constraint (be careful to scale it by dt properly).
I found all these differences by comparing the impulse engine github repo with Catto's Box2D Lite github repo. I suggest anyone else curious about evolving from the impulse method to the sequential impulses method to compare these two repositories.
To figure out how to derive the differences between the repositories, then go to box2d.org/downloads. Erin Catto has documented his derivation very well in his earlier GDC lectures. Erin had a background where he understood classical mechanics, and then noted that his strategy of clamping and caching the accumulated impulse was equivalent to a Gauss-Seidel matrix solver, thus mathematically proving his strategy to be a good one.
The naive impulse strategy was used for many years before Erin's materials were published, and at the time other people were using similar strategies to Erin, but it was all more or less difficult information to find and learn about (or just plain kept secret). For example, we can see back in 1995 the same equations popping up in Chris Hecker's nice magazine article. These equations will be found in Erin's resources, but expanded upon after arriving at them from a different strategy with more abstract math.