What is the difference of
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.
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.
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:
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):
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.
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):
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.
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
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.
Could not loop the gif perfectly... sigh. The block does not stutter in the actual sim, but continues to rotate smoothly.