Class DistanceJoint
One of the simplest joint is a distance joint which says that the distance between two points on two bodies must be constant. When you specify a distance joint the two bodies should already be in place. Then you specify the two anchor points in world coordinates. The first anchor point is connected to body 1, and the second anchor point is connected to body 2. These points imply the length of the distance constraint.
Here is an example of a distance joint definition. In this case we decide to allow the bodies to collide.
The distance joint can also be made soft, like a spring-damper connection.
Softness is achieved by tuning two constants in the definition: stiffness and damping. It can be non-intuitive setting these values directly since they have units in terms on Newtons.
Think of the frequency as the frequency of a harmonic oscillator (like a guitar string). The frequency is specified in Hertz. Typically the frequency should be less than a half the frequency of the time step. So if you are using a 60Hz time step, the frequency of the distance joint should be less than 30Hz. The reason is related to the Nyquist frequency.
The damping ratio is non-dimensional and is typically between 0 and 1, but can be larger. At 1, the damping is critical (all oscillations should vanish).
It is also possible to define a minimum and maximum length for the distance joint.
- Author:
- Daniel Murphy
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidgetAnchorA(Vec2 argOut) Get the anchor point on bodyA in world coordinates.voidgetAnchorB(Vec2 argOut) Get the anchor point on bodyB in world coordinates.floatfloatfloatGet the rest length.Get the local anchor point relative to bodyA's origin.Get the local anchor point relative to bodyB's origin.voidgetReactionForce(float invDt, Vec2 argOut) Get the reaction force given the inverse time step.floatgetReactionTorque(float invDt) Get the reaction torque given the inverse time step.voidInternalvoidsetDampingRatio(float damp) voidsetFrequency(float hz) voidsetLength(float length) Set the rest length.booleanThis returns true if the position errors are within tolerance.voidInternalMethods inherited from class org.jbox2d.dynamics.joints.Joint
create, destroy, destructor, getBodyA, getBodyB, getCollideConnected, getNext, getType, getUserData, isActive, setUserData
-
Constructor Details
-
DistanceJoint
-
-
Method Details
-
initVelocityConstraints
Description copied from class:JointInternal- Specified by:
initVelocityConstraintsin classJoint
-
solveVelocityConstraints
Description copied from class:JointInternal- Specified by:
solveVelocityConstraintsin classJoint
-
solvePositionConstraints
Description copied from class:JointThis returns true if the position errors are within tolerance. Internal.- Specified by:
solvePositionConstraintsin classJoint
-
getAnchorA
Description copied from class:JointGet the anchor point on bodyA in world coordinates.- Specified by:
getAnchorAin classJoint
-
getAnchorB
Description copied from class:JointGet the anchor point on bodyB in world coordinates.- Specified by:
getAnchorBin classJoint
-
getReactionForce
Get the reaction force given the inverse time step. Unit is N.- Specified by:
getReactionForcein classJoint
-
getReactionTorque
public float getReactionTorque(float invDt) Get the reaction torque given the inverse time step. Unit is N*m. This is always zero for a distance joint.- Specified by:
getReactionTorquein classJoint
-
getLength
public float getLength()Get the rest length.- Returns:
- The rest length.
-
setLength
public void setLength(float length) Set the rest length. -
setFrequency
public void setFrequency(float hz) -
getFrequency
public float getFrequency() -
setDampingRatio
public void setDampingRatio(float damp) -
getDampingRatio
public float getDampingRatio() -
getLocalAnchorA
Get the local anchor point relative to bodyA's origin.- Returns:
- The local anchor point relative to bodyA's origin.
-
getLocalAnchorB
Get the local anchor point relative to bodyB's origin.- Returns:
- The local anchor point relative to bodyB's origin.
-