Confused abotu solver math, J M-1 Jt

Hi,

I made an example on paper for 3 bodies connected with 2 constraints, in my math,
body 1 -> distance constraint 1 -> body2 -> distance constraint 2 -> body 3
using notation of Erin Catto's 2005 presentation (http://box2d.googlecode.com/files/GDC2005_ErinCatto.zip), pages 16,
the J M-1 Jt matrix shows that for the 1st constraint, the solution to delta-lambda needs A11 and A12
and in this case A12 is not zero, it has terms from the jacobian of the second constraint.

But on page 17, I see that this term is ignored is this correct? because if not
the delta-lambda term in page 17 should have many terms subtracted from ni and not only Jsp(i,1).A(b1) and Jsp(i,2).A(b2), but could be many others,
actually I think each constraint related to body 1 or body 2 will be there.

Are we removing these terms? I am stuck on this I wanted to try to write a small solver.
Sorry if this is a stupid question, thank you very much.

My example math:
Code:
3 bodies, 2 constraints.

J: 2x(18)
Jt: 18x2
M and M-1 : 18 x 18


                                6 cols          6 cols              6 cols
J     constraint1   |  Jac1(body1)   Jac1(body2)   0                  |
      constraint2    |  0                 Jac2(body2)   Jac2(body3)   |



M-1 Jt (18x2)                         ctrt1                ctrt2
                              |   Jac1(body1)/M1            0                      |   6 rows
                              |   Jac1(body2)/M2         Jac2(body2)/M2     |   6 rows
                              |   0                             Jac2(body3)/M2     |   6 rows

Now J M-1 Jt (2x2)

                              |  Jac1(B1).Jac1(B1)/M1 + Jac1(B2).Jac1(B2)/M2               Jac1(B2).Jac2(B2)/M2                                 |
                              |  Jac2(B2).Jac1(B2)/M2                                               Jac2(B2).Jac2(B2)/M2 + Jac2(B3).Jac2(B3)/M3 |


The lambda-delta in page 17 only takes the diagonal terms of this 2x2 matrix, so
for ctrt1, Jac1(B1).Jac1(B1)/M1 + Jac1(B2).Jac1(B2)/M2 is Jsp(i,1).A(b1)+Jsp(i,2).A(b2), but where is Jac1(B2).Jac2(B2)/M2 ?
Each constraint affects two bodies. So for constraint 1 we have A11 affecting body 1 and A12 affecting body2, both non-zero in general. These pair-wise entries are in the J and B matrices. The formulas on page 17 reflect that constraints are only pair-wise (affecting just two bodies at a time). We don't need to consider a full matrix.
Hello Erin,

Thanks for the reply.

I want to be sure I understand this.
In my specific example A12 is not zero, but if we would use the algorithm of page 17, it would be treated as zero, is that correct?
is this an approximation we make?

what I mean is:
In the J matrix, for one constraint, the row has non-zero entries for the 2 bodies it contains and zeros for the rest.
In the M-1 Jt, for one constraint, the column has non-zero entries for the 2 bodies it contains and zeros for the rest.
in the J M-1 Jt matrix however, the linear equation for the lambda of the 1st constraint,has the diagonal (A11) entry non-zero, this is always the case
even if the constraint was the only one in the system, but other entries (A12 in the example) and A13, A14... in general will be non-zero for all constraints that
share some body with constraint 1, so for solving the lambda, all constraints that share a body with constraint 1 will have to appear, but none of these terms appear in the algorithm of page 17, only the diagonal ones, solving each constraint 'in isolation',
are you saying we ignore all these terms as an approximation? if not where do they appear?

When you say full matrix, you mean a full s x s (s number of constraints) matrix? and you mean we don't 'need' because we approximate? or because the sxs matrix ONLY has diagonal elements? because in this case I don't understand, since even in my simple example that's not true...

Thank you...
SanjayM wrote:
In my specific example A12 is not zero, but if we would use the algorithm of page 17, it would be treated as zero, is that correct?


No, that is not correct. There are no ignored values. There are no matrix approximations. The only approximation is the solution (because GS is approximate).

The algorithm is taking advantage of the sparseness of J and M. You may have a hard time seeing this because of the vector a. Keep in mind that the algorithm is solving for lambda, but the vector a is holding B * lambda.

I think the text already explains this. In the end you will understand the algorithm best if you implement it and check the values.

Quote:
We also modify the linear algebra of Algorithm 3 to exploit the sparsity of J and
B. Thus, we avoid forming the s-by-s matrix JB. This is crucial for improving
performance and reducing memory requirements.

Algorithm 4 shows the Projected Gauss-Seidel method. For simplicity, we have
ignored the case where b1= 0 (indicating ground). First the algorithm creates the
temporary vectors a and d. The vector a is initialized with the product Bλ, which
can be computed in a fashion similar to Algorithm 2. The vector d is initialized
with the diagonal elements of JB. Note that the elements of J, B, η, and a are
stored as 6-vectors. Each time an increment to λiis computed, λiis clamped to its
bounds and the actual increment is determined. With the actual increment of λi,
the vector a is updated so that it remains equal to Bλ.
OK thank you very much! I will 🙂

Original thread: https://box2d.org/forum/viewtopic.php?t=7702