4
\$\begingroup\$

What is the difference of b2WeldJoint and b2DistanceJoint? They both have frequency and also when you put frequency of Distance Joint to 0 it acts like Weld Joint. It seams that you can create Distance Joint effect using Weld Jonit and vice versa.

\$\endgroup\$
6
\$\begingroup\$

Thanks for asking Narek. I've struggled with understanding these joints in the past, and I'd like to use this answer to clear up some misconceptions.

b2DistanceJoint

This joint has two input parameters: frequency w, and damping d. Together they define the linear response of the connected bodies. Here I will always consider one body as the ground body (set to b2StaticBody) and the other is called the mass (set to b2DynamicBody) for simplicity.

To understand the effects of varying the frequency and damping parameters, lets setup a grid of 9 ground and mass bodies where the frequency varies between rows, while the damping varies between columns:

setup

The simulation is initialized with all joints 0.5m offset from their rest length. Here is a gif of what happens when I run this (using RUBE):

springs_gif

As we can see, the frequency controls how fast the oscillations occur, while the damping controls the rate at which the oscillations are damped out.

b2WeldJoint

The description given in the docs is:

A weld joint essentially glues two bodies together. A weld joint may distort somewhat because the island constraint solver is approximate.

Given the name and the description it appears that the primary intention of the weld joint is to fix the relative movement of bodies, but that's not strictly how it functions, which is why I disagree with the naming of the b2WeldJoint. It's function would be a lot clearer if it was named b2AngleJoint. This is because it functions as the angular analogue of the the b2DistanceJoint (i.e. the frequency and damping parameters work the same way, except they apply to the angle rather than the linear offset):

weld_joint

EDIT: The b2WeldJoint is used as a flexible joint in the box2d testbed cantilever demo. To me anyway, this indicates that the joint can (at least sometimes) be used as a flexible joint.

Difference

The difference is the b2DistanceJoint only affects the relative distance between the bodies, whereas the b2WeldJoint affects the relative angle while restricting the radial motion. i.e. bodies connected by b2DistanceJoints can rotate around one another freely, while bodies connected via b2WeldJoints will always tend to fixed relative positions.

So the claim that b2DistanceJoints and b2WeldJoints with frequencies of 0 are the same is false. In the counter example below b2DistanceJoint is on left, b2WeldJoint on right, both with zero frequency and initial velocities v=0,1 for both the masses.

distance_&_weld

Could not loop the gif perfectly... sigh. The block does not stutter in the actual sim, but continues to rotate smoothly.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks for the great answer! Never thought about Weld Joint in that perspective. But, I guess, in the case when it tries to recover the angle, with oscillations like a distance joint recovered the distance explains a lot. I only don't understand whether it is a side effect of a solver approximation or this joint is intended to be used as AngleJoint and in not named well as you point out. \$\endgroup\$
    – Narek
    Apr 27 '15 at 6:34
  • \$\begingroup\$ @Narek See the edit to my answer. \$\endgroup\$ Apr 28 '15 at 18:31
  • \$\begingroup\$ @Narek Also, if you find this answer fully answers your question it would be helpful to the community if you accepted it :) \$\endgroup\$ Apr 28 '15 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.