-
- Type Parameters:
T
- thePhysicsBody
type
- All Implemented Interfaces:
DataContainer
,Shiftable
,Ownable
public class RevoluteJoint<T extends PhysicsBody> extends Joint<T> implements Shiftable, DataContainer
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 the lower and upper limits are set explicitly, the values must follow these restrictions:
- lower limit ≤ upper limit
- lower limit > -180
- upper limit < 180
setReferenceAngle(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 joint.setLimits(Math.toRadians(-60), Math.toRadians(170)); joint.setReferenceAngle(Math.toRadians(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.- Since:
- 1.0.0
- Version:
- 4.0.1
- Author:
- William Bittle
- See Also:
- Documentation, Point-to-Point Constraint
-
-
Constructor Summary
Constructors Constructor Description RevoluteJoint(T body1, T body2, Vector2 anchor)
Minimal constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Vector2
getAnchor1()
Returns the anchor point on the firstPhysicsBody
in world coordinates.Vector2
getAnchor2()
Returns the anchor point on the secondPhysicsBody
in world coordinates.double
getJointAngle()
Returns the relative angle between the twoPhysicsBody
s in radians in the range [-π, π].double
getJointSpeed()
Returns the relative speed at which thePhysicsBody
s are rotating in radians/second.LimitState
getLimitState()
Deprecated.Deprecated in 4.0.0.double
getLowerLimit()
Returns the lower rotational limit in radians.double
getMaximumMotorTorque()
Returns the maximum torque this motor will apply in newton-meters.double
getMotorSpeed()
Returns the desired motor speed in radians/second.double
getMotorTorque()
Returns the motor torque in newton-meters.Vector2
getReactionForce(double invdt)
Returns the force applied to thePhysicsBody
s in order to satisfy the constraint in newtons.double
getReactionTorque(double invdt)
Returns the torque applied to thePhysicsBody
s in order to satisfy the constraint in newton-meters.double
getReferenceAngle()
Returns the reference angle.double
getUpperLimit()
Returns the upper rotational limit in radians.void
initializeConstraints(TimeStep step, Settings settings)
Performs any initialization of the velocity and position constraints.boolean
isLimitEnabled()
Returns true if the rotational limit is enabled.boolean
isMotorEnabled()
Returns true if this motor is enabled.void
setLimitEnabled(boolean flag)
Enables or disables the rotational limit.void
setLimits(double lowerLimit, double upperLimit)
Sets the upper and lower rotational limits.void
setLowerLimit(double lowerLimit)
Sets the lower rotational limit.void
setMaximumMotorTorque(double maximumMotorTorque)
Sets the maximum torque this motor will apply in newton-meters.void
setMotorEnabled(boolean flag)
Sets whether the motor for this joint is enabled or not.void
setMotorSpeed(double motorSpeed)
Sets the target motor speed in radians/second.void
setReferenceAngle(double angle)
Sets the reference angle.void
setUpperLimit(double upperLimit)
Sets the upper rotational 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 Joint
getBody1, getBody2, getOtherBody, getOwner, getUserData, isActive, isCollisionAllowed, isEnabled, isOnIsland, setCollisionAllowed, setOnIsland, setOwner, setUserData
-
Methods inherited from interface DataContainer
getUserData, setUserData
-
-
-
-
Constructor Detail
-
RevoluteJoint
public RevoluteJoint(T body1, T body2, Vector2 anchor)
Minimal constructor.- Parameters:
body1
- the firstPhysicsBody
body2
- the secondPhysicsBody
anchor
- the anchor point in world coordinates- Throws:
NullPointerException
- if body1, body2 or anchor is nullIllegalArgumentException
- if body1 == body2
-
-
Method Detail
-
toString
public String toString()
- Overrides:
toString
in classJoint<T extends PhysicsBody>
-
initializeConstraints
public void initializeConstraints(TimeStep step, Settings settings)
Description copied from class:Joint
Performs any initialization of the velocity and position constraints.- Specified by:
initializeConstraints
in classJoint<T extends PhysicsBody>
- Parameters:
step
- the time step informationsettings
- the current world settings
-
solveVelocityConstraints
public void solveVelocityConstraints(TimeStep step, Settings settings)
Description copied from class:Joint
Solves the velocity constraints.- Specified by:
solveVelocityConstraints
in classJoint<T extends PhysicsBody>
- Parameters:
step
- the time step informationsettings
- the current world settings
-
solvePositionConstraints
public boolean solvePositionConstraints(TimeStep step, Settings settings)
Description copied from class:Joint
Solves the position constraints.- Specified by:
solvePositionConstraints
in classJoint<T extends PhysicsBody>
- Parameters:
step
- the time step informationsettings
- the current world settings- Returns:
- boolean true if the position constraints were solved
-
getAnchor1
public Vector2 getAnchor1()
Description copied from class:Joint
Returns the anchor point on the firstPhysicsBody
in world coordinates.- Specified by:
getAnchor1
in classJoint<T extends PhysicsBody>
- Returns:
Vector2
-
getAnchor2
public Vector2 getAnchor2()
Description copied from class:Joint
Returns the anchor point on the secondPhysicsBody
in world coordinates.- Specified by:
getAnchor2
in classJoint<T extends PhysicsBody>
- Returns:
Vector2
-
getReactionForce
public Vector2 getReactionForce(double invdt)
Description copied from class:Joint
Returns the force applied to thePhysicsBody
s in order to satisfy the constraint in newtons.- Specified by:
getReactionForce
in classJoint<T extends PhysicsBody>
- Parameters:
invdt
- the inverse delta time- Returns:
Vector2
-
getReactionTorque
public double getReactionTorque(double invdt)
Description copied from class:Joint
Returns the torque applied to thePhysicsBody
s in order to satisfy the constraint in newton-meters.- Specified by:
getReactionTorque
in classJoint<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.
-
getJointSpeed
public double getJointSpeed()
Returns the relative speed at which thePhysicsBody
s are rotating in radians/second.- Returns:
- double
-
getJointAngle
public double getJointAngle()
Returns the relative angle between the twoPhysicsBody
s in radians in the range [-π, π].- Returns:
- double
-
isMotorEnabled
public boolean isMotorEnabled()
Returns true if this motor is enabled.- Returns:
- boolean
-
setMotorEnabled
public void setMotorEnabled(boolean flag)
Sets whether the motor for this joint is enabled or not.- Parameters:
flag
- true if the motor should be enabled
-
getMaximumMotorTorque
public double getMaximumMotorTorque()
Returns the maximum torque this motor will apply in newton-meters.- Returns:
- double
-
setMaximumMotorTorque
public void setMaximumMotorTorque(double maximumMotorTorque)
Sets the maximum torque this motor will apply in newton-meters.- Parameters:
maximumMotorTorque
- the maximum motor torque in newton-meters; must be greater than or equal to zero- Throws:
IllegalArgumentException
- if maxMotorTorque is less than zero- See Also:
setMotorSpeed(double)
-
getMotorSpeed
public double getMotorSpeed()
Returns the desired motor speed in radians/second.- Returns:
- double
-
setMotorSpeed
public void setMotorSpeed(double motorSpeed)
Sets the target motor speed in radians/second.- Parameters:
motorSpeed
- the motor speed desired in radians/second- See Also:
setMaximumMotorTorque(double)
-
getMotorTorque
public double getMotorTorque()
Returns the motor torque in newton-meters.- Returns:
- double
-
isLimitEnabled
public boolean isLimitEnabled()
Returns true if the rotational limit is enabled.- Returns:
- boolean
-
setLimitEnabled
public void setLimitEnabled(boolean flag)
Enables or disables the rotational limit.- Parameters:
flag
- true if the limit should be enabled
-
getUpperLimit
public double getUpperLimit()
Returns the upper rotational limit in radians.- Returns:
- double
-
setUpperLimit
public void setUpperLimit(double upperLimit)
Sets the upper rotational limit.Must be greater than or equal to the lower rotational limit.
See the class documentation for more details on the limit ranges.
- Parameters:
upperLimit
- the upper rotational limit in radians- Throws:
IllegalArgumentException
- if upperLimit is less than the current lower limit
-
getLowerLimit
public double getLowerLimit()
Returns the lower rotational limit in radians.- Returns:
- double
-
setLowerLimit
public void setLowerLimit(double lowerLimit)
Sets the lower rotational limit.Must be less than or equal to the upper rotational limit.
See the class documentation for more details on the limit ranges.
- Parameters:
lowerLimit
- the lower rotational limit in radians- Throws:
IllegalArgumentException
- if lowerLimit is greater than the current upper limit
-
setLimits
public void setLimits(double lowerLimit, double upperLimit)
Sets the upper and lower rotational 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.
- Parameters:
lowerLimit
- the lower limit in radiansupperLimit
- the upper limit in radians- Throws:
IllegalArgumentException
- if the lowerLimit is greater than upperLimit
-
getReferenceAngle
public double getReferenceAngle()
Returns the 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.
- Returns:
- double
- Since:
- 3.0.1
-
setReferenceAngle
public void setReferenceAngle(double angle)
Sets the 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.
- Parameters:
angle
- the reference angle in radians- Since:
- 3.0.1
- See Also:
getReferenceAngle()
-
getLimitState
@Deprecated public LimitState getLimitState()
Deprecated.Deprecated in 4.0.0.Returns the current state of the limit.- Returns:
LimitState
- Since:
- 3.2.0
-
-