Module org.dyn4j

Class PinJoint

  • All Implemented Interfaces:
    DataContainer, Shiftable

    public class PinJoint
    extends Joint
    implements Shiftable, DataContainer
    Implementation of a pin joint.

    A pin joint is a joint that pins a body to a specified world space point using a spring-damper system. This joint will attempt to place the given anchor point at the target position.

    NOTE: The anchor point does not have to be within the bounds of the body.

    By default the target position will be the given world space anchor. Use the setTarget(Vector2) method to set a different target.

    The pin joint requires the spring-damper system to function properly and as such the frequency value must be greater than zero. Use a RevoluteJoint instead if a spring-damper system is not desired. A good starting point is a frequency of 8.0 and damping ratio of 0.3 then adjust as necessary.

    The getAnchor1() method returns the target and the getAnchor2() method returns the world space anchor point.

    Both the Constraint.getBody1() and Constraint.getBody2() methods return the same body.

    Renamed from MouseJoint in 3.2.0.

    Since:
    1.0.0
    Version:
    3.2.1
    Author:
    William Bittle
    See Also:
    Documentation
    • Field Detail

      • target

        protected Vector2 target
        The world space target point
      • anchor

        protected Vector2 anchor
        The local anchor point for the body
      • frequency

        protected double frequency
        The oscillation frequency in hz
      • dampingRatio

        protected double dampingRatio
        The damping ratio
      • maximumForce

        protected double maximumForce
        The maximum force this constraint can apply
    • Constructor Detail

      • PinJoint

        public PinJoint​(Body body,
                        Vector2 anchor,
                        double frequency,
                        double dampingRatio,
                        double maximumForce)
        Full constructor.
        Parameters:
        body - the body to attach the joint to
        anchor - the anchor point on the body
        frequency - the oscillation frequency in hz
        dampingRatio - the damping ratio
        maximumForce - the maximum force this constraint can apply in newtons
        Throws:
        java.lang.NullPointerException - if body or anchor is null
        java.lang.IllegalArgumentException - if frequency is less than or equal to zero, or if dampingRatio is less than zero or greater than one, or if maxForce is less than zero
    • 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()
        Returns the anchor point on the first Body in world coordinates.

        Returns the target point in world space.

        Specified by:
        getAnchor1 in class Joint
        Returns:
        Vector2
      • getAnchor2

        public Vector2 getAnchor2()
        Returns the anchor point on the second Body in world coordinates.

        Returns the anchor point on the body in world space.

        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
      • isCollisionAllowed

        public boolean isCollisionAllowed()
        Description copied from class: Joint
        Returns true if collision between the joined Bodys is allowed.
        Overrides:
        isCollisionAllowed in class Joint
        Returns:
        boolean
      • 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
      • setTarget

        public void setTarget​(Vector2 target)
        Returns the target point in world coordinates.
        Parameters:
        target - the target point
        Throws:
        java.lang.NullPointerException - if target is null
      • getTarget

        public Vector2 getTarget()
        Returns the target point in world coordinates
        Returns:
        Vector2
      • getMaximumForce

        public double getMaximumForce()
        Returns the maximum force this constraint will apply in newtons.
        Returns:
        double
      • setMaximumForce

        public void setMaximumForce​(double maximumForce)
        Sets the maximum force this constraint will apply in newtons.
        Parameters:
        maximumForce - the maximum force in newtons; in the range [0, ∞]
        Throws:
        java.lang.IllegalArgumentException - if maxForce less than zero
      • getDampingRatio

        public double getDampingRatio()
        Returns the damping ratio.
        Returns:
        double
      • setDampingRatio

        public void setDampingRatio​(double dampingRatio)
        Sets the damping ratio.
        Parameters:
        dampingRatio - the damping ratio; in the range [0, 1]
        Throws:
        java.lang.IllegalArgumentException - if dampingRation is less than zero or greater than one
      • getFrequency

        public double getFrequency()
        Returns the spring frequency.
        Returns:
        double
      • setFrequency

        public void setFrequency​(double frequency)
        Sets the spring frequency.
        Parameters:
        frequency - the spring frequency in hz; must be greater than zero
        Throws:
        java.lang.IllegalArgumentException - if frequency is less than or equal to zero