Module org.dyn4j

Class PinJoint<T extends PhysicsBody>

  • Type Parameters:
    T - the PhysicsBody type
    All Implemented Interfaces:
    DataContainer, Shiftable, Ownable

    public class PinJoint<T extends PhysicsBody>
    extends Joint<T>
    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 Joint.getBody1() and Joint.getBody2() methods return the same body.

    Renamed from MouseJoint in 3.2.0.

    Since:
    1.0.0
    Version:
    4.0.0
    Author:
    William Bittle
    See Also:
    Documentation
    • Constructor Detail

      • PinJoint

        public PinJoint​(T 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:
        NullPointerException - if body or anchor is null
        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

      • 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 class Joint<T extends PhysicsBody>
        Parameters:
        step - the time step information
        settings - 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 class Joint<T extends PhysicsBody>
        Parameters:
        step - the time step information
        settings - 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 class Joint<T extends PhysicsBody>
        Parameters:
        step - the time step information
        settings - the current world settings
        Returns:
        boolean true if the position constraints were solved
      • getReactionForce

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

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

        Not applicable to this joint. Always returns zero.

        Specified by:
        getReactionTorque in class Joint<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.
        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:
        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:
        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:
        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:
        IllegalArgumentException - if frequency is less than or equal to zero