Module org.dyn4j

## Class RevoluteJoint<T extends PhysicsBody>

• Type Parameters:
`T` - the `PhysicsBody` type
All Implemented Interfaces:
`DataContainer`, `AngularLimitsJoint`, `AngularMotorJoint`, `Joint<T>`, `PairedBodyJoint<T>`, `Shiftable`, `Ownable`

```public class RevoluteJoint<T extends PhysicsBody>
extends AbstractPairedBodyJoint<T>
implements AngularLimitsJoint, AngularMotorJoint, PairedBodyJoint<T>, Joint<T>, Shiftable, DataContainer, Ownable```
Implementation of a pivot joint.

A pivot joint allows two bodies to rotate freely about a common point, but does not allow them to translate relative to one another. The system as a whole can translate and rotate freely.

By default the lower and upper limit angles are set to the current angle between the bodies. When the lower and upper limits are equal, the bodies rotate together and are not allowed rotate relative to one another. By default the limits are disabled. If you want the lower and upper limit to be the same, use a `WeldJoint` instead.

If the lower and upper limits are set explicitly, the values must follow these restrictions:

• lower limit ≤ upper limit
• lower limit > -180
• upper limit < 180
To create a joint with limits outside of this range use the `setLimitsReferenceAngle(double)` method. This method sets the baseline angle for the joint, which represents 0 radians in the context of the limits. For example:
``` // we would like the joint limits to be [30, 260]
// this is the same as the limits [-60, 170] if the reference angle is 90
```
This joint also supports a motor. The motor is an angular motor about the anchor point. The motor speed can be positive or negative to indicate a clockwise or counter-clockwise rotation. The maximum motor torque must be greater than zero for the motor to apply any motion, but can be disabled or enabled using `setMaximumMotorTorqueEnabled(boolean)`.
Since:
1.0.0
Version:
5.0.0
Author:
William Bittle
Documentation, Point-to-Point Constraint
• ### Field Summary

Fields
Modifier and Type Field Description
`protected boolean` `limitsEnabled`
Whether the `Joint` limits are enabled or not
`protected Vector2` `localAnchor1`
The local anchor point on the first `PhysicsBody`
`protected Vector2` `localAnchor2`
The local anchor point on the second `PhysicsBody`
`protected double` `lowerLimit`
The lower limit of the `Joint`
`protected boolean` `motorEnabled`
Whether the motor for this `Joint` is enabled or not
`protected double` `motorMaximumTorque`
The maximum torque the motor can apply
`protected boolean` `motorMaximumTorqueEnabled`
True if the motor maximum torque has been enabled
`protected double` `motorSpeed`
The target motor speed; in radians / second
`protected double` `referenceAngle`
The initial angle between the two `PhysicsBody`s
`protected double` `upperLimit`
The upper limit of the `Joint`
• ### Fields inherited from class AbstractPairedBodyJoint

`body1, body2`
• ### Fields inherited from class AbstractJoint

`bodies, collisionAllowed, owner, userData`
• ### Fields inherited from interface Joint

`SPRING_MODE_FREQUENCY, SPRING_MODE_STIFFNESS`
• ### Constructor Summary

Constructors
Constructor Description
```RevoluteJoint​(T body1, T body2, Vector2 anchor)```
Minimal constructor.
• ### Method Summary

All Methods
Modifier and Type Method Description
`Vector2` `getAnchor1()`
The anchor point in world space on the first body.
`Vector2` `getAnchor2()`
The anchor point in world space on the second body.
`double` `getAngularSpeed()`
Returns the relative speed at which the `PhysicsBody`s are rotating in radians/second.
`double` `getAngularTranslation()`
Returns the relative angle between the two `PhysicsBody`s in radians in the range [-π, π].
`double` `getLimitsReferenceAngle()`
Returns the limits reference angle.
`double` `getLowerLimit()`
Returns the lower angular limit in radians.
`double` `getMaximumMotorTorque()`
Returns the maximum torque the motor can apply to the joint to achieve the target speed.
`double` `getMotorSpeed()`
Returns the target motor speed in radians / second.
`double` `getMotorTorque​(double invdt)`
Returns the applied motor torque.
`Vector2` `getReactionForce​(double invdt)`
Returns the force applied to the `PhysicsBody`s in order to satisfy the constraint in newtons.
`double` `getReactionTorque​(double invdt)`
Returns the torque applied to the `PhysicsBody`s in order to satisfy the constraint in newton-meters.
`double` `getUpperLimit()`
Returns the upper angular limit in radians.
`void` ```initializeConstraints​(TimeStep step, Settings settings)```
Performs any initialization of the velocity and position constraints.
`boolean` `isLimitsEnabled()`
Returns true if the angular limits are enabled.
`boolean` `isMaximumMotorTorqueEnabled()`
Returns true if the maximum motor torque is enabled.
`boolean` `isMotorEnabled()`
Returns true if the motor is enabled.
`void` `setLimits​(double limit)`
Sets both the lower and upper limits to the given limit.
`void` ```setLimits​(double lowerLimit, double upperLimit)```
Sets the upper and lower angular limits.
`void` `setLimitsEnabled​(boolean flag)`
Enables or disables the angular limits.
`void` `setLimitsEnabled​(double limit)`
Sets both the lower and upper limits to the given limit and enables them.
`void` ```setLimitsEnabled​(double lowerLimit, double upperLimit)```
Sets both the lower and upper limits and enables them.
`void` `setLimitsReferenceAngle​(double angle)`
Sets the limits reference angle.
`void` `setLowerLimit​(double lowerLimit)`
Sets the lower angular limit.
`void` `setMaximumMotorTorque​(double maximumMotorTorque)`
Sets the maximum torque the motor can apply to the joint to achieve the target speed.
`void` `setMaximumMotorTorqueEnabled​(boolean enabled)`
Sets whether the maximum motor torque is enabled.
`void` `setMotorEnabled​(boolean flag)`
Enables or disables the motor.
`void` `setMotorSpeed​(double motorSpeed)`
Sets the target motor speed.
`void` `setUpperLimit​(double upperLimit)`
Sets the upper angular limit.
`void` `shift​(Vector2 shift)`
Translates the object to match the given coordinate shift.
`boolean` ```solvePositionConstraints​(TimeStep step, Settings settings)```
Solves the position constraints.
`void` ```solveVelocityConstraints​(TimeStep step, Settings settings)```
Solves the velocity constraints.
`String` `toString()`
• ### Methods inherited from class AbstractPairedBodyJoint

`getBody, getBody1, getBody2, getBodyCount, getOtherBody, getReducedInertia, getReducedMass, isEnabled, isMember, setCollisionAllowed`
• ### Methods inherited from class AbstractJoint

`getBodies, getBodyIterator, getConstraintImpulseMixing, getErrorReductionParameter, getFrequency, getNaturalFrequency, getNaturalFrequency, getOwner, getSpringDampingCoefficient, getSpringStiffness, getUserData, isCollisionAllowed, setOwner, setUserData`
• ### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Methods inherited from interface DataContainer

`getUserData, setUserData`
• ### Methods inherited from interface Joint

`getBodies, getBody, getBodyCount, getBodyIterator, isCollisionAllowed, isEnabled, isMember, setCollisionAllowed`
• ### Methods inherited from interface Ownable

`getOwner, setOwner`
• ### Methods inherited from interface PairedBodyJoint

`getBody1, getBody2, getOtherBody`
• ### Field Detail

• #### localAnchor1

`protected final Vector2 localAnchor1`
The local anchor point on the first `PhysicsBody`
• #### localAnchor2

`protected final Vector2 localAnchor2`
The local anchor point on the second `PhysicsBody`
• #### limitsEnabled

`protected boolean limitsEnabled`
Whether the `Joint` limits are enabled or not
• #### upperLimit

`protected double upperLimit`
The upper limit of the `Joint`
• #### lowerLimit

`protected double lowerLimit`
The lower limit of the `Joint`
• #### referenceAngle

`protected double referenceAngle`
The initial angle between the two `PhysicsBody`s
• #### motorEnabled

`protected boolean motorEnabled`
Whether the motor for this `Joint` is enabled or not
• #### motorSpeed

`protected double motorSpeed`
The target motor speed; in radians / second
• #### motorMaximumTorqueEnabled

`protected boolean motorMaximumTorqueEnabled`
True if the motor maximum torque has been enabled
• #### motorMaximumTorque

`protected double motorMaximumTorque`
The maximum torque the motor can apply
• ### Constructor Detail

• #### RevoluteJoint

```public RevoluteJoint​(T body1,
T body2,
Vector2 anchor)```
Minimal constructor.
Parameters:
`body1` - the first `PhysicsBody`
`body2` - the second `PhysicsBody`
`anchor` - the anchor point in world coordinates
Throws:
`NullPointerException` - if body1, body2 or anchor is null
`IllegalArgumentException` - if body1 == body2
• ### Method Detail

• #### toString

`public String toString()`
Overrides:
`toString` in class `AbstractJoint<T extends PhysicsBody>`
• #### initializeConstraints

```public void initializeConstraints​(TimeStep step,
Settings settings)```
Description copied from interface: `Joint`
Performs any initialization of the velocity and position constraints.
Specified by:
`initializeConstraints` in interface `Joint<T extends PhysicsBody>`
Parameters:
`step` - the time step information
`settings` - the current world settings
• #### solveVelocityConstraints

```public void solveVelocityConstraints​(TimeStep step,
Settings settings)```
Description copied from interface: `Joint`
Solves the velocity constraints.
Specified by:
`solveVelocityConstraints` in interface `Joint<T extends PhysicsBody>`
Parameters:
`step` - the time step information
`settings` - the current world settings
• #### solvePositionConstraints

```public boolean solvePositionConstraints​(TimeStep step,
Settings settings)```
Description copied from interface: `Joint`
Solves the position constraints.
Specified by:
`solvePositionConstraints` in interface `Joint<T extends PhysicsBody>`
Parameters:
`step` - the time step information
`settings` - the current world settings
Returns:
boolean true if the position constraints were solved
• #### getAnchor1

`public Vector2 getAnchor1()`
The anchor point in world space on the first body.
Returns:
`Vector2`
• #### getAnchor2

`public Vector2 getAnchor2()`
The anchor point in world space on the second body.
Returns:
`Vector2`
• #### getReactionForce

`public Vector2 getReactionForce​(double invdt)`
Description copied from interface: `Joint`
Returns the force applied to the `PhysicsBody`s in order to satisfy the constraint in newtons.
Specified by:
`getReactionForce` in interface `Joint<T extends PhysicsBody>`
Parameters:
`invdt` - the inverse delta time
Returns:
`Vector2`
• #### getReactionTorque

`public double getReactionTorque​(double invdt)`
Description copied from interface: `Joint`
Returns the torque applied to the `PhysicsBody`s in order to satisfy the constraint in newton-meters.
Specified by:
`getReactionTorque` in interface `Joint<T extends PhysicsBody>`
Parameters:
`invdt` - the inverse delta time
Returns:
double
• #### shift

`public void shift​(Vector2 shift)`
Description copied from interface: `Shiftable`
Translates the object to match the given coordinate shift.
Specified by:
`shift` in interface `Shiftable`
Parameters:
`shift` - the amount to shift along the x and y axes
• #### getAngularSpeed

`public double getAngularSpeed()`
Returns the relative speed at which the `PhysicsBody`s are rotating in radians/second.
Returns:
double
• #### getAngularTranslation

`public double getAngularTranslation()`
Returns the relative angle between the two `PhysicsBody`s in radians in the range [-π, π].
Returns:
double
• #### isMotorEnabled

`public boolean isMotorEnabled()`
Description copied from interface: `AngularMotorJoint`
Returns true if the motor is enabled.
Specified by:
`isMotorEnabled` in interface `AngularMotorJoint`
Returns:
boolean
• #### setMotorEnabled

`public void setMotorEnabled​(boolean flag)`
Description copied from interface: `AngularMotorJoint`
Enables or disables the motor.
Specified by:
`setMotorEnabled` in interface `AngularMotorJoint`
Parameters:
`flag` - true if the motor should be enabled
• #### getMaximumMotorTorque

`public double getMaximumMotorTorque()`
Description copied from interface: `AngularMotorJoint`
Returns the maximum torque the motor can apply to the joint to achieve the target speed.
Specified by:
`getMaximumMotorTorque` in interface `AngularMotorJoint`
Returns:
double
• #### setMaximumMotorTorque

`public void setMaximumMotorTorque​(double maximumMotorTorque)`
Description copied from interface: `AngularMotorJoint`
Sets the maximum torque the motor can apply to the joint to achieve the target speed.
Specified by:
`setMaximumMotorTorque` in interface `AngularMotorJoint`
Parameters:
`maximumMotorTorque` - the maximum torque in newtons-meters; in the range (0, ∞]
`AngularMotorJoint.setMotorSpeed(double)`
• #### setMaximumMotorTorqueEnabled

`public void setMaximumMotorTorqueEnabled​(boolean enabled)`
Description copied from interface: `AngularMotorJoint`
Sets whether the maximum motor torque is enabled.
Specified by:
`setMaximumMotorTorqueEnabled` in interface `AngularMotorJoint`
Parameters:
`enabled` - true if the maximum motor torque should be enabled
• #### isMaximumMotorTorqueEnabled

`public boolean isMaximumMotorTorqueEnabled()`
Description copied from interface: `AngularMotorJoint`
Returns true if the maximum motor torque is enabled.
Specified by:
`isMaximumMotorTorqueEnabled` in interface `AngularMotorJoint`
Returns:
boolean
• #### getMotorSpeed

`public double getMotorSpeed()`
Description copied from interface: `AngularMotorJoint`
Returns the target motor speed in radians / second.
Specified by:
`getMotorSpeed` in interface `AngularMotorJoint`
Returns:
double
• #### setMotorSpeed

`public void setMotorSpeed​(double motorSpeed)`
Description copied from interface: `AngularMotorJoint`
Sets the target motor speed.
Specified by:
`setMotorSpeed` in interface `AngularMotorJoint`
Parameters:
`motorSpeed` - the target motor speed in radians / second
`AngularMotorJoint.setMaximumMotorTorque(double)`
• #### getMotorTorque

`public double getMotorTorque​(double invdt)`
Description copied from interface: `AngularMotorJoint`
Returns the applied motor torque.
Specified by:
`getMotorTorque` in interface `AngularMotorJoint`
Parameters:
`invdt` - the inverse delta time from the time step
Returns:
double
• #### isLimitsEnabled

`public boolean isLimitsEnabled()`
Description copied from interface: `AngularLimitsJoint`
Returns true if the angular limits are enabled.
Specified by:
`isLimitsEnabled` in interface `AngularLimitsJoint`
Returns:
boolean
• #### setLimitsEnabled

`public void setLimitsEnabled​(boolean flag)`
Description copied from interface: `AngularLimitsJoint`
Enables or disables the angular limits.
Specified by:
`setLimitsEnabled` in interface `AngularLimitsJoint`
Parameters:
`flag` - true if the limit should be enabled
• #### getUpperLimit

`public double getUpperLimit()`
Description copied from interface: `AngularLimitsJoint`
Returns the upper angular limit in radians.
Specified by:
`getUpperLimit` in interface `AngularLimitsJoint`
Returns:
double
• #### setUpperLimit

`public void setUpperLimit​(double upperLimit)`
Description copied from interface: `AngularLimitsJoint`
Sets the upper angular limit.

Must be greater than or equal to the lower angular limit.

See the class documentation for more details on the limit ranges.

Specified by:
`setUpperLimit` in interface `AngularLimitsJoint`
Parameters:
`upperLimit` - the upper angular limit in radians
• #### getLowerLimit

`public double getLowerLimit()`
Description copied from interface: `AngularLimitsJoint`
Returns the lower angular limit in radians.
Specified by:
`getLowerLimit` in interface `AngularLimitsJoint`
Returns:
double
• #### setLowerLimit

`public void setLowerLimit​(double lowerLimit)`
Description copied from interface: `AngularLimitsJoint`
Sets the lower angular limit.

Must be less than or equal to the upper angular limit.

See the class documentation for more details on the limit ranges.

Specified by:
`setLowerLimit` in interface `AngularLimitsJoint`
Parameters:
`lowerLimit` - the lower angular limit in radians
• #### setLimits

```public void setLimits​(double lowerLimit,
double upperLimit)```
Description copied from interface: `AngularLimitsJoint`
Sets the upper and lower angular limits.

The lower limit must be less than or equal to the upper limit.

See the class documentation for more details on the limit ranges.

Specified by:
`setLimits` in interface `AngularLimitsJoint`
Parameters:
`lowerLimit` - the lower limit in radians
`upperLimit` - the upper limit in radians
• #### setLimitsEnabled

```public void setLimitsEnabled​(double lowerLimit,
double upperLimit)```
Description copied from interface: `AngularLimitsJoint`
Sets both the lower and upper limits and enables them.

See the class documentation for more details on the limit ranges.

Specified by:
`setLimitsEnabled` in interface `AngularLimitsJoint`
Parameters:
`lowerLimit` - the lower limit in radians
`upperLimit` - the upper limit in radians
• #### setLimitsEnabled

`public void setLimitsEnabled​(double limit)`
Description copied from interface: `AngularLimitsJoint`
Sets both the lower and upper limits to the given limit and enables them.

See the class documentation for more details on the limit ranges.

Specified by:
`setLimitsEnabled` in interface `AngularLimitsJoint`
Parameters:
`limit` - the desired limit
• #### setLimits

`public void setLimits​(double limit)`
Description copied from interface: `AngularLimitsJoint`
Sets both the lower and upper limits to the given limit.

See the class documentation for more details on the limit ranges.

Specified by:
`setLimits` in interface `AngularLimitsJoint`
Parameters:
`limit` - the desired limit
• #### getLimitsReferenceAngle

`public double getLimitsReferenceAngle()`
Description copied from interface: `AngularLimitsJoint`
Returns the limits reference angle.

The reference angle is the angle calculated when the joint was created from the two joined bodies. The reference angle is the angular difference between the bodies.

Specified by:
`getLimitsReferenceAngle` in interface `AngularLimitsJoint`
Returns:
double
• #### setLimitsReferenceAngle

`public void setLimitsReferenceAngle​(double angle)`
Description copied from interface: `AngularLimitsJoint`
Sets the limits reference angle.

This method can be used to set the reference angle to override the computed reference angle from the constructor. This is useful in recreating the joint from a current state or when adjusting the limits.

See the class documentation for more details.

Specified by:
`setLimitsReferenceAngle` in interface `AngularLimitsJoint`
Parameters:
`angle` - the reference angle in radians
`AngularLimitsJoint.getLimitsReferenceAngle()`