- Object
-
- AbstractJoint<T>
-
- AbstractPairedBodyJoint<T>
-
- AngleJoint<T>
-
- Type Parameters:
T
- thePhysicsBody
type
- All Implemented Interfaces:
DataContainer
,AngularLimitsJoint
,Joint<T>
,PairedBodyJoint<T>
,Shiftable
,Ownable
public class AngleJoint<T extends PhysicsBody> extends AbstractPairedBodyJoint<T> implements AngularLimitsJoint, PairedBodyJoint<T>, Joint<T>, Shiftable, DataContainer, Ownable
Implementation of an angle joint.A angle joint constrains the relative rotation of two bodies. The bodies will continue to translate 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 enabled.
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
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 joint.setLimits(Math.toRadians(-60), Math.toRadians(170)); joint.setReferenceAngle(Math.toRadians(90));
The angle joint also allows a ratio value that allow the bodies to rotate at a specified value relative to the other. This can be used to simulate gears.Since the AngleJoint class defaults the upper and lower limits to the same value and by default the limits are enabled, you will need to disable the limit to see the effect of the ratio.
- Since:
- 2.2.2
- Version:
- 5.0.0
- Author:
- William Bittle
- See Also:
- Documentation, Angle Constraint
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
limitsEnabled
Whether the limits are enabledprotected double
lowerLimit
The lower limitprotected double
ratio
The angular velocity ratioprotected double
referenceAngle
The initial angle between the two bodiesprotected double
upperLimit
The upper limit-
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 AngleJoint(T body1, T body2)
Minimal constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
getJointAngle()
Returns the relative angle between the twoPhysicsBody
s in radians in the range [-π, π].double
getLimitsReferenceAngle()
Returns the limits reference angle.double
getLowerLimit()
Returns the lower angular limit in radians.double
getRatio()
Returns the angular velocity ratio between the two bodies.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
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.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
setRatio(double ratio)
Sets the angular velocity ratio between the two bodies.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 PairedBodyJoint
getBody1, getBody2, getOtherBody
-
-
-
-
Field Detail
-
ratio
protected double ratio
The angular velocity ratio
-
lowerLimit
protected double lowerLimit
The lower limit
-
upperLimit
protected double upperLimit
The upper limit
-
limitsEnabled
protected boolean limitsEnabled
Whether the limits are enabled
-
referenceAngle
protected double referenceAngle
The initial angle between the two bodies
-
-
Constructor Detail
-
AngleJoint
public AngleJoint(T body1, T body2)
Minimal constructor.- Parameters:
body1
- the firstPhysicsBody
body2
- the secondPhysicsBody
- Throws:
NullPointerException
- if body1 or body2 is nullIllegalArgumentException
- if body1 == body2
-
-
Method Detail
-
toString
public String toString()
- Overrides:
toString
in classAbstractJoint<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 interfaceJoint<T extends PhysicsBody>
- Parameters:
step
- the time step informationsettings
- 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 interfaceJoint<T extends PhysicsBody>
- Parameters:
step
- the time step informationsettings
- 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 interfaceJoint<T extends PhysicsBody>
- Parameters:
step
- the time step informationsettings
- the current world settings- Returns:
- boolean true if the position constraints were solved
-
getReactionForce
public Vector2 getReactionForce(double invdt)
Returns the force applied to thePhysicsBody
s in order to satisfy the constraint in newtons.Not applicable to this joint. Returns a new zero
Vector2
.- Specified by:
getReactionForce
in interfaceJoint<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 thePhysicsBody
s in order to satisfy the constraint in newton-meters.- Specified by:
getReactionTorque
in interfaceJoint<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.
-
getJointAngle
public double getJointAngle()
Returns the relative angle between the twoPhysicsBody
s in radians in the range [-π, π].- Returns:
- double
- Since:
- 3.1.0
-
getRatio
public double getRatio()
Returns the angular velocity ratio between the two bodies.- Returns:
- double
- Since:
- 3.1.0
-
setRatio
public void setRatio(double ratio)
Sets the angular velocity ratio between the two bodies.A value of 0.5 means that body1 will rotate 2 times while body2 rotates once. A value of 2 means that body2 will rotate 2 times while body1 rotates once.
A value of 1.0 means that the body rotate at the same rate.
A negative ratio indicates that the anglular velocities of the joined bodies should be in opposite directions.
A ratio of zero is not supported.
- Parameters:
ratio
- the ratio; anything, just not zero- Throws:
IllegalArgumentException
- if ratio is equal to zero- Since:
- 3.1.0
-
setLimitsEnabled
public void setLimitsEnabled(boolean flag)
Description copied from interface:AngularLimitsJoint
Enables or disables the angular limits.- Specified by:
setLimitsEnabled
in interfaceAngularLimitsJoint
- Parameters:
flag
- true if the limit should be enabled
-
isLimitsEnabled
public boolean isLimitsEnabled()
Description copied from interface:AngularLimitsJoint
Returns true if the angular limits are enabled.- Specified by:
isLimitsEnabled
in interfaceAngularLimitsJoint
- Returns:
- boolean
-
getUpperLimit
public double getUpperLimit()
Description copied from interface:AngularLimitsJoint
Returns the upper angular limit in radians.- Specified by:
getUpperLimit
in interfaceAngularLimitsJoint
- 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 interfaceAngularLimitsJoint
- 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 interfaceAngularLimitsJoint
- 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 interfaceAngularLimitsJoint
- 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 interfaceAngularLimitsJoint
- Parameters:
lowerLimit
- the lower limit in radiansupperLimit
- 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 interfaceAngularLimitsJoint
- Parameters:
lowerLimit
- the lower limit in radiansupperLimit
- the upper limit in radians
-
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 interfaceAngularLimitsJoint
- Parameters:
limit
- the desired limit
-
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 interfaceAngularLimitsJoint
- 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 interfaceAngularLimitsJoint
- 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 interfaceAngularLimitsJoint
- Parameters:
angle
- the reference angle in radians- See Also:
AngularLimitsJoint.getLimitsReferenceAngle()
-
-