Module org.dyn4j

Class PulleyJoint

  • All Implemented Interfaces:
    DataContainer, Shiftable

    public class PulleyJoint
    extends Joint
    implements Shiftable, DataContainer
    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. Values between 0 and 1 exclusive indicate that the first body's rope length will be 1/x times longer than the second body's rope length. Values between 1 and infinity indicate that the second body's rope length will be x times longer than the first body's rope length.

    By default this joint acts very similar to two DistanceJoints 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 in true to the setSlackEnabled(boolean) method.

    Since:
    2.1.0
    Version:
    3.2.1
    Author:
    William Bittle
    See Also:
    Documentation, Pulley Constraint
    • Field Detail

      • pulleyAnchor1

        protected Vector2 pulleyAnchor1
        The world space pulley anchor point for the first Body
      • pulleyAnchor2

        protected Vector2 pulleyAnchor2
        The world space pulley anchor point for the second Body
      • localAnchor1

        protected Vector2 localAnchor1
        The local anchor point on the first Body
      • localAnchor2

        protected Vector2 localAnchor2
        The local anchor point on the second Body
      • 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​(Body body1,
                           Body body2,
                           Vector2 pulleyAnchor1,
                           Vector2 pulleyAnchor2,
                           Vector2 bodyAnchor1,
                           Vector2 bodyAnchor2)
        Minimal constructor.

        Creates a pulley joint between the two given Bodys using the given anchor points.

        Parameters:
        body1 - the first Body
        body2 - the second Body
        pulleyAnchor1 - the first pulley anchor point
        pulleyAnchor2 - the second pulley anchor point
        bodyAnchor1 - the first Body's anchor point
        bodyAnchor2 - the second Body's anchor point
        Throws:
        java.lang.NullPointerException - if body1, body2, pulleyAnchor1, pulleyAnchor2, bodyAnchor1, or bodyAnchor2 is null
        java.lang.IllegalArgumentException - if body1 == body2
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class Joint
      • initializeConstraints

        public void initializeConstraints​(Step step,
                                          Settings settings)
        Description copied from class: Joint
        Performs any initialization of the velocity and position constraints.
        Specified by:
        initializeConstraints in class Joint
        Parameters:
        step - the time step information
        settings - the current world settings
      • solveVelocityConstraints

        public void solveVelocityConstraints​(Step step,
                                             Settings settings)
        Description copied from class: Joint
        Solves the velocity constraints.
        Specified by:
        solveVelocityConstraints in class Joint
        Parameters:
        step - the time step information
        settings - the current world settings
      • solvePositionConstraints

        public boolean solvePositionConstraints​(Step step,
                                                Settings settings)
        Description copied from class: Joint
        Solves the position constraints.
        Specified by:
        solvePositionConstraints in class Joint
        Parameters:
        step - the time step information
        settings - 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 first Body in world coordinates.
        Specified by:
        getAnchor1 in class Joint
        Returns:
        Vector2
      • getAnchor2

        public Vector2 getAnchor2()
        Description copied from class: Joint
        Returns the anchor point on the second Body in world coordinates.
        Specified by:
        getAnchor2 in class Joint
        Returns:
        Vector2
      • getReactionForce

        public Vector2 getReactionForce​(double invdt)
        Description copied from class: Joint
        Returns the force applied to the Bodys in order to satisfy the constraint in newtons.
        Specified by:
        getReactionForce in class Joint
        Parameters:
        invdt - the inverse delta time
        Returns:
        Vector2
      • getReactionTorque

        public double getReactionTorque​(double invdt)
        Returns the torque applied to the Bodys in order to satisfy the constraint in newton-meters.

        Not applicable to this joint. Always returns zero.

        Specified by:
        getReactionTorque in class Joint
        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
      • getPulleyAnchor1

        public Vector2 getPulleyAnchor1()
        Returns the pulley anchor point for the first Body in world coordinates.
        Returns:
        Vector2
      • getPulleyAnchor2

        public Vector2 getPulleyAnchor2()
        Returns the pulley anchor point for the second Body in world coordinates.
        Returns:
        Vector2
      • getLength

        public double getLength()
        Returns the total length of the pulley "rope."
        Returns:
        double
        Since:
        3.0.1
        See Also:
        setLength(double)
      • 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
        Since:
        3.2.1
      • getLength1

        public double getLength1()
        Returns the current length from the first pulley anchor point to the anchor point on the first Body.

        This is used, in conjunction with length2, to compute the total length when the ratio is changed.

        Returns:
        double
      • getLength2

        public double getLength2()
        Returns the current length from the second pulley anchor point to the anchor point on the second Body.

        This is used, in conjunction with length1, to compute the total length when the ratio is changed.

        Returns:
        double
      • 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.

        This method recomputes the total length of the pulley system.

        Parameters:
        ratio - the ratio; must be greater than zero
        Throws:
        java.lang.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
      • getLimitState

        public LimitState getLimitState()
        Returns the current state of the limit.
        Returns:
        LimitState
        Since:
        3.2.0