Comments on: Equality Constraints http://www.codezealot.org/archives/191 Development blog and open source repository by William Bittle Sat, 18 Oct 2014 13:53:50 +0000 hourly 1 http://wordpress.org/?v=4.0 By: Nick http://www.codezealot.org/archives/191#comment-126110 Sun, 13 Jul 2014 22:58:47 +0000 http://www.codezealot.org/?p=191#comment-126110 Thanks a lot William, that clears it up for me. :)

]]>
By: William http://www.codezealot.org/archives/191#comment-126107 Sun, 13 Jul 2014 22:21:30 +0000 http://www.codezealot.org/?p=191#comment-126107 @Nick

Ok, thanks for elaborating.

Yeah, you can solve the compound constraints separately for sure. The problem with doing it that way is that it will be less accurate. This manifests itself as requiring more iterations of the global solver (which will solve every constraint every iteration). As a result, it’s much faster, and more accurate, to solve them together when possible.

Aside from this, some small benefits include better encapsulation along with some other niceties (for example allowing the toggling/configuring of various properties of the joints (which could reduce or increase the number of DOF that are solved) without the caller destroying or creating new joints.

William

]]>
By: Nick http://www.codezealot.org/archives/191#comment-125991 Sun, 13 Jul 2014 06:12:17 +0000 http://www.codezealot.org/?p=191#comment-125991 Hi William,

Thanks for your reply. That makes sense, although maybe I didn’t explain my question well enough. I’ll try to explain what I meant better, but please excuse me if any of the following is wrong as I’m still trying to figure it out :)

What I meant was, say you have a system with several constraints (eg a weld joint between bodies 1 and 2, and a revolute joint between bodies 2 and 3). As you say, you can either create a large sparse matrix for all bodies that will have both of the constraints in it, and solve that, or you can apply an iterative method.
Like you described, the iterative method would work by solving each constraint in isolation, and then repeating this a number of times.

Some constraints are made by composing others (for example the weld joint is a revolute joint combined with an angle joint). What I was wondering is, just as you can consider the two constraints I mentioned above in isolation (when solving iteratively), does this mean you could also consider the 2 constraints of the weld joint separately in the iterative solver?

If I understand correctly, when fully expanded (rather than in block form) the Jacobian for the weld joint will actually have 3 rows, one for each degree of freedom removed.
That is, there is a scalar constraint equation to restrict each of the X, Y and angle of one body relative to the other.
What I really was getting at was, can each of *these* be considered in isolation (as separate constraints) when writing an iterative solver?

The reason I wanted to know that is because if K and lambda is scalar then lambda can be solved for directly, rather than having to worry about inverting K. And also from Catto’s GDC 2009 presentation he seems to describe K and lambda as scalars, so I assumed that’s what he meant, but then I see in the code he doesn’t do that so I am confused.

Hope that makes more sense.

]]>
By: William http://www.codezealot.org/archives/191#comment-125944 Sat, 12 Jul 2014 16:24:20 +0000 http://www.codezealot.org/?p=191#comment-125944 @Nick

There are two types of constraints that you may be referring to here. There are equality constraints, which are typically your joint formulations, and inequality constraints which include contacts (for collision resolution). For now lets focus on equality constraints.

Equality constraints can be solved using any linear solver, this is true. For example, if you look at the implementation, in the InitVelocityConstraints method, it inverts the K matrix (which I call the A matrix). Later, in the SolveVelocityConstraints method, it multiplies the K matrix with the cdot or cdo1 (which I call the b vector). Computing the inverse of a matrix and multiplying it by a vector is identical to solving a system of equations.

This solves the joint exactly, however, there’s an issue when you have more than one constraint. Let’s say you solve them one after another. You solve the first constraint exactly, then you move to the next one and solve it exactly, and so on. But as you are solve each subsequent constraint, the previous constraint’s solutions may be invalidated. What is required is a global solution. This is where the iterative solver comes in. Put simply, the iterative solver solves all joints, one after another, n number of times. It’s been shown that this will converge to the global solution. An alternative to an iterative solver is to put all the Ax = b equations into a giant matrix and solve it, but there are a lot of advantages to the iterative method, especially for real time simulation and when coupled with inequality constraints.

William

]]>
By: Nick http://www.codezealot.org/archives/191#comment-125888 Sat, 12 Jul 2014 03:48:40 +0000 http://www.codezealot.org/?p=191#comment-125888 Hi William,
I think your site is the best resource on the net for this topic, and was so glad when I finally found it. Thanks a lot for putting it together!

You mention solving for lambda using a linear equation solver, but I see in Erin Catto’s Box2D papers that he uses an iterative method.
I just wanted to ask, for the constraints where the Jacobian is a matrix rather than a scalar, is it possible to solve for lambda by treating each Jacobian row as a separate constraint? Otherwise I don’t understand how an iterative method would work with these Jacobians.

]]>
By: William http://www.codezealot.org/archives/191#comment-125722 Thu, 10 Jul 2014 23:24:32 +0000 http://www.codezealot.org/?p=191#comment-125722 @Jiang Jin hao

You’ve probably found your answer already, but it’s a good idea to respond since it will help others. Take a look a slide 15 . This should explain where equation 2 comes from. It contains a lot of other good information too.

William

]]>
By: Jiang Jin hao http://www.codezealot.org/archives/191#comment-124257 Wed, 02 Jul 2014 07:32:38 +0000 http://www.codezealot.org/?p=191#comment-124257 hi~William
First of all, thanks a lot for the marvelous post.
I’m a chinese student,so please tolerate the nonproficiency of my English.
I can understand the computing process except for the equation[2] on the post.
Appreciate for your apply, thank you ~

]]>
By: William http://www.codezealot.org/archives/191#comment-22572 Sat, 14 Jan 2012 17:36:24 +0000 http://www.codezealot.org/?p=191#comment-22572 Yeah, I should do this. Unfortunately, I don’t have all my links and pdfs that had originally used as references… I went back through some of my references and here is what I could find. It’s not much but it can get you started. The 3rd link has over 150 references at the end that cover a number of topics. (Thats how I typically go about finding information, endless references lookup using google)

– David Baraff
– Erin Catto GDC Slides
– Large reference for a number of topics
– A small list of references

]]>
By: marco http://www.codezealot.org/archives/191#comment-22531 Sat, 14 Jan 2012 04:23:55 +0000 http://www.codezealot.org/?p=191#comment-22531 Hello,

This is a very good description of constraint forces at play in physical systems. If you can, can you let us know what books/papers you have referenced in this theoretical development? I would like to learn more.

]]>
By: juhl http://www.codezealot.org/archives/191#comment-17209 Mon, 07 Nov 2011 19:37:00 +0000 http://www.codezealot.org/?p=191#comment-17209 Thanks a lot !
What a silly question. haha.
Maybe I was confused with many block matrix.

]]>