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


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.
  3. Isolate the velocity.




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


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)




5 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

Leave a Reply

