- Object
-
- AbstractJoint<T>
-
- AbstractPairedBodyJoint<T>
-
- PulleyJoint<T>
-
- Type Parameters:
T
- thePhysicsBody
type
- All Implemented Interfaces:
DataContainer
,Joint<T>
,PairedBodyJoint<T>
,Shiftable
,Ownable
public class PulleyJoint<T extends PhysicsBody> extends AbstractPairedBodyJoint<T> implements PairedBodyJoint<T>, Joint<T>, Shiftable, DataContainer, Ownable
Implementation of a pulley joint.A pulley joint joins two bodies in a pulley system with a fixed length zero mass rope. The bodies are allowed to rotate freely. The bodies are allowed to translate freely up to the total length of the "rope."
The length of the "rope" connecting the two bodies is computed by distance from the pulley anchors to the body anchors including the ratio (if any) when the joint is created. The length can be changed dynamically by calling the
setLength(double)
method.The pulley anchor points represent the "hanging" points for the respective bodies and can be any world space point.
This joint can also model a block-and-tackle system by setting the ratio using the
setRatio(double)
method. A value of 1.0 indicates no ratio. For all values of the ratio, the length of the "rope" stays constant. The ratio applies only when computing the impulse between the two bodies. If the ratio is between 0 and 1 exclusive, the second body exhibits the effect of having 1/x more mass. If the ration is greater than 1, the first body exhibits the effect of having x more mass.By default this joint acts very similar to two
DistanceJoint
s in that the bodies are forced to be their respective rope-distance away from the pulley anchors (i.e. not behaving like a rope). To have the bodies behave as if connected by flexible rope pass intrue
to thesetSlackEnabled(boolean)
method.- Since:
- 2.1.0
- Version:
- 5.0.0
- Author:
- William Bittle
- See Also:
- Documentation, Pulley Constraint
-
-
Field Summary
Fields Modifier and Type Field Description protected Vector2
localAnchor1
The local anchor point on the firstPhysicsBody
protected Vector2
localAnchor2
The local anchor point on the secondPhysicsBody
protected Vector2
pulleyAnchor1
The world space pulley anchor point for the firstPhysicsBody
protected Vector2
pulleyAnchor2
The world space pulley anchor point for the secondPhysicsBody
protected double
ratio
The pulley ratio for modeling a block-and-tackleprotected boolean
slackEnabled
True if slack in the rope is enabled-
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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vector2
getAnchor1()
Returns the world space anchor point on the first body.Vector2
getAnchor2()
Returns the world space anchor point on the second body.double
getCurrentLength()
Returns the current length of the pulley "rope."double
getCurrentLength1()
Returns the current length from the first pulley anchor point to the anchor point on the firstPhysicsBody
.double
getCurrentLength2()
Returns the current length from the second pulley anchor point to the anchor point on the secondPhysicsBody
.double
getLength()
Returns the target total length of the pulley "rope."Vector2
getPulleyAnchor1()
Returns the pulley anchor point for the firstPhysicsBody
in world coordinates.Vector2
getPulleyAnchor2()
Returns the pulley anchor point for the secondPhysicsBody
in world coordinates.double
getRatio()
Returns the pulley ratio.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.void
initializeConstraints(TimeStep step, Settings settings)
Performs any initialization of the velocity and position constraints.boolean
isSlackEnabled()
Returns true if slack in the rope is enabled.void
setLength(double length)
Sets the total length of the pulley "rope."void
setRatio(double ratio)
Sets the pulley ratio.void
setSlackEnabled(boolean flag)
Toggles the slack in the rope.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
-
pulleyAnchor1
protected final Vector2 pulleyAnchor1
The world space pulley anchor point for the firstPhysicsBody
-
pulleyAnchor2
protected final Vector2 pulleyAnchor2
The world space pulley anchor point for the secondPhysicsBody
-
localAnchor1
protected final Vector2 localAnchor1
The local anchor point on the firstPhysicsBody
-
localAnchor2
protected final Vector2 localAnchor2
The local anchor point on the secondPhysicsBody
-
ratio
protected double ratio
The pulley ratio for modeling a block-and-tackle
-
slackEnabled
protected boolean slackEnabled
True if slack in the rope is enabled
-
-
Constructor Detail
-
PulleyJoint
public PulleyJoint(T body1, T body2, Vector2 pulleyAnchor1, Vector2 pulleyAnchor2, Vector2 bodyAnchor1, Vector2 bodyAnchor2)
Minimal constructor.Creates a pulley joint between the two given
PhysicsBody
s using the given anchor points.- Parameters:
body1
- the firstPhysicsBody
body2
- the secondPhysicsBody
pulleyAnchor1
- the first pulley anchor pointpulleyAnchor2
- the second pulley anchor pointbodyAnchor1
- the firstPhysicsBody
's anchor pointbodyAnchor2
- the secondPhysicsBody
's anchor point- Throws:
NullPointerException
- if body1, body2, pulleyAnchor1, pulleyAnchor2, bodyAnchor1, or bodyAnchor2 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
-
getAnchor1
public Vector2 getAnchor1()
Returns the world space anchor point on the first body.- Returns:
Vector2
-
getAnchor2
public Vector2 getAnchor2()
Returns the world space anchor point on the second body.- Returns:
Vector2
-
getReactionForce
public Vector2 getReactionForce(double invdt)
Description copied from interface:Joint
Returns the force applied to thePhysicsBody
s in order to satisfy the constraint in newtons.- Specified by:
getReactionForce
in interfaceJoint<T extends PhysicsBody>
- Parameters:
invdt
- the inverse delta time- Returns:
Vector2
-
getReactionTorque
public double getReactionTorque(double invdt)
Returns the torque applied to thePhysicsBody
s in order to satisfy the constraint in newton-meters.Not applicable to this joint. Always returns zero.
- 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.
-
getPulleyAnchor1
public Vector2 getPulleyAnchor1()
Returns the pulley anchor point for the firstPhysicsBody
in world coordinates.- Returns:
Vector2
-
getPulleyAnchor2
public Vector2 getPulleyAnchor2()
Returns the pulley anchor point for the secondPhysicsBody
in world coordinates.- Returns:
Vector2
-
getLength
public double getLength()
Returns the target total length of the pulley "rope."NOTE: this is the target length with the ratio taken into account.
- Returns:
- double
- Since:
- 3.0.1
- See Also:
setLength(double)
-
getCurrentLength
public double getCurrentLength()
Returns the current length of the pulley "rope."This should always be close to, or equal to, the
getLength()
.- Returns:
- double
- Since:
- 4.2.0
-
setLength
public void setLength(double length)
Sets the total length of the pulley "rope."Typically this is computed when the joint is created by adding the distance from the first body anchor to the first pulley anchor with the distance from the second body anchor to the second pulley anchor.
- Parameters:
length
- the length; must be greater than or equal to zero- Throws:
IllegalArgumentException
- if length is less than zero- Since:
- 3.2.1
-
getCurrentLength1
public double getCurrentLength1()
Returns the current length from the first pulley anchor point to the anchor point on the firstPhysicsBody
.This is used, in conjunction with length2, to compute the total length when the ratio is changed.
- Returns:
- double
- Since:
- 4.2.0
-
getCurrentLength2
public double getCurrentLength2()
Returns the current length from the second pulley anchor point to the anchor point on the secondPhysicsBody
.This is used, in conjunction with length1, to compute the total length when the ratio is changed.
- Returns:
- double
- Since:
- 4.2.0
-
getRatio
public double getRatio()
Returns the pulley ratio.- Returns:
- double
-
setRatio
public void setRatio(double ratio)
Sets the pulley ratio.The ratio value is used to simulate a block-and-tackle. A ratio of 1.0 is the default and indicates that the pulley is not a block-and-tackle.
A ratio in the range (0, 1) indicates that the second body weighs more. A ratio in the range of (1, ∞] indicates that the first body weighs more.
- Parameters:
ratio
- the ratio; must be greater than zero- Throws:
IllegalArgumentException
- if ratio is less than or equal to zero
-
isSlackEnabled
public boolean isSlackEnabled()
Returns true if slack in the rope is enabled.- Returns:
- boolean
- Since:
- 3.1.6
-
setSlackEnabled
public void setSlackEnabled(boolean flag)
Toggles the slack in the rope.If slack is not enabled the rope length is fixed to the total length of the rope, acting like the
DistanceJoint
.- Parameters:
flag
- true to enable slack- Since:
- 3.1.6
-
-