Weld Constraint

The next equality constraint we will derive is the weld constraint. A weld constraint can be used to join two bodies at an anchor point in which the bodies must move and rotate together (all DOF are constrained).

This post will differ slightly from the previous posts. A weld joint is basically a revolute joint + an angle joint. In that case we can use the resulting Jacobians from those posts to skip a bit of the work.

  1. Problem Definition
  2. Process Overview
  3. The Jacobian
  4. Compute The K Matrix

Problem Definition
It’s probably good to start with a good definition of what we are trying to accomplish.

We want to take two or more bodies and constrain their motion in some way. For instance, say we want two bodies to only be able to rotate about a common point (Revolute Joint). The most common application are constraints between pairs of bodies. Because we have constrained the motion of the bodies, we must find the correct velocities, so that constraints are satisfied otherwise the integrator would allow the bodies to move forward along their current paths. To do this we need to create equations that allow us to solve for the velocities.

What follows is the derivation of the equations needed to solve for a Weld constraint.

Process Overview
Let’s review the process:

  1. Create a position constraint equation.
  2. Perform the derivative with respect to time to obtain the velocity constraint.
  3. Isolate the velocity.

Using these steps we can ensure that we get the correct velocity constraint. After isolating the velocity we inspect the equation to find J, the Jacobian.

Most constraint solvers today solve on the velocity level. Earlier work solved on the acceleration level.

Once the Jacobian is found we use that to compute the K matrix. The K matrix is the A in the Ax = b general form equation.

The Jacobian
Like stated above, the weld constraint is just a combination of two other constraints: point-to-point and angle constraints. As such, we can simply combine the Jacobians we found for those constraints into one Jacobain:

weldc (5)

See the “Point-to-Point Constraint” and “Angle Constraint” posts for the derivation of their Jacobians.

Compute The K Matrix
Lastly, to solve the constraint we need to compute the values for A (I use the name K) and b:

See the “Equality Constraints” post for the derivation of the A matrix and b vector.

ptpc (1)

For this constraint the b vector computation isn’t as simple as in past constraints. So I’ll work this out as well:

weldc (6)

Notice here that the first element in the b vector is a vector also. This makes the b vector a 3×1 vector instead of the normal 2×1 that we have seen thus far.

Now on to computing the K matrix:

weldc (7)

Multiplying left to right the first two matrices we obtain:

weldc (8)

Multiplying left to right again:

weldc (9)

Unlike previous posts, some of the elements in the above matrix are matrices themselves. When we multiply out the elements we’ll see that the resulting K matrix is actually a 3×3 matrix.

It makes sense that the K matrix is a 3×3 because the b vector was a 3×1, meaning we have 3 variables to solve for. The b vector and K matrix dimensions must match.

So lets take each element and work them out separately, starting with the first element. We can actually copy the result from the Point-to-Point constraint post since its exactly the same:

weldc (10)

Now let move on to the second element. If we remember:

weldc (1)

So multiplying and adding the vectors here yields the matrix:

weldc (2)

Likewise, for the third element:

weldc (3)

Lastly the last element can be left as is since its just a scalar.

Now adding all these elements back into one big matrix we obtain:

weldc (4)

Plug the values of the K matrix and b vector into your linear equation solver and you will get the impulse required to satisfy the constraint.

Note here that if you are using an iterative solver that the K matrix does not change over iterations and as such can be computed once each time step.

Another interesting thing to note is that the K matrix will always be a square matrix with a size equal to the number of degrees of freedom (DOF) removed. This is a good way to check that the derivation was performed correctly.

7 thoughts on “Weld Constraint

  • Pingback: Constraints Composition – Weld Constraint | The Little Balance
  • Pingback: Constraints Composition – Weld Constraint | The Little Balance
  • Hi William,

    When combining a revolute joint and an angle constraint to form the 2×2 block K matrix consisting of four 3×3 matrices below for an elbow joint with restricted angular movement, how do I invert this matrix to solve for lambda, which seems like another matrix of two 3×1 vectors as follows:

    A*lambda = b

    A = JM^-1JT

    A11 = Ma^-1 + [~ra]TIa^-1[~ra] + Mb^-1 + [~rb]TIb^-1[~rb]
    A12 = [~ra]TIa^-1 + [~rb]TIb^-1
    A21 = Ia^-1[~ra] + Ib^-1[~rb]
    A22 = Ia^-1 + Ib^-1

    b = -Jvi

    b11 = -va – [~ra]Twa + vb + [~rb]Twb
    b12 = -wa + wb

    A*lambda = b

    I am working in 3D, so multiplying the matrices out gets really messy

    Thanks for another great tutorial

    • Yeah, working in 3D is much harder since multiplying out the matrices symbolically is messy. The good thing is, once you have identified the Jacobian you don’t really have to go much further (one reason to go further is to find places where you can improve performance). You can just use the equations below, fill in all the numbers and do the matrix multiplication then.

      This should yield a 6×6 matrix (each row has 2 3×3 columns). To solve this we need to have a b vector that is 6×1.

      We can see that the first row will yield a 3×1 as will the bottom. So we should be able to solve this 6 variable system using whatever linear equation solver you would like to use. To solve this you must invert the 6×6. You can use Gaussian Elimination, LU Decomposition, Cholesky Decomposition, etc just be careful of singularities and the respective algorithm’s restrictions.

      Another option is to use an application like Mathematica (or something similar) to simplify the matrices symbolically (since it isn’t really hard, just tedious).

      Hope that helps,

  • Thanks William, that helps.

    I have temporarily just applied the revolute joint and restricted angle joint separately to both bodies and it seems to be doing the trick.

    For the elbow angle:

    currAngleDiff = body1.orientation – body2.orientation
    if(currAngleDiff.z>=0 && currAngleDiff.z<=radians(130) skip constraint, assuming the arm is straight at first at angle zero

    Hope that helps anyone

  • I must say it was hard to find your blog in search results.

    You write awesome articles but you should rank your website higher in search
    engines. If you don’t know how to do it search on youtube:
    how to rank a website Marcel’s way

  • Skype has launched its internet-structured customer
    beta for the entire world, right after introducing it extensively
    within the United states and U.K. previous this month.
    Skype for Internet also now works with Linux
    and Chromebook for instant text messaging interaction (no video and voice nevertheless, those demand a connect-in installment).

    The increase from the beta provides help for a longer selection of spoken languages to aid strengthen that
    worldwide usability

Leave a Reply

Your email address will not be published. Required fields are marked *