Module org.dyn4j

Class PinJoint<T extends PhysicsBody>

    • Field Detail

      • target

        protected final Vector2 target
        The world space target point
      • localAnchor

        protected final Vector2 localAnchor
        The local anchor point for the body
      • springEnabled

        protected boolean springEnabled
        True if the spring is enabled
      • springMode

        protected int springMode
        The current spring mode
      • springFrequency

        protected double springFrequency
        The oscillation frequency in hz
      • springStiffness

        protected double springStiffness
        The stiffness (k) of the spring
      • springDamperEnabled

        protected boolean springDamperEnabled
        True if the spring's damper is enabled
      • springDampingRatio

        protected double springDampingRatio
        The damping ratio
      • springMaximumForceEnabled

        protected boolean springMaximumForceEnabled
        True if the spring maximum force is enabled
      • springMaximumForce

        protected double springMaximumForce
        The maximum force the spring can apply
      • correctionFactor

        protected double correctionFactor
        The correction factor in the range [0, 1]
      • correctionMaximumForce

        protected double correctionMaximumForce
        The maximum force the constraint can apply
    • Constructor Detail

      • PinJoint

        public PinJoint​(T body,
                        Vector2 anchor)
        Full constructor.
        Parameters:
        body - the body to attach the joint to
        anchor - the anchor point on the body
        Throws:
        NullPointerException - if body or anchor is null
    • Method Detail

      • 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 interface 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 interface: Joint
        Solves the velocity constraints.
        Specified by:
        solveVelocityConstraints in interface 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 interface: Joint
        Solves the position constraints.
        Specified by:
        solvePositionConstraints in interface Joint<T extends PhysicsBody>
        Parameters:
        step - the time step information
        settings - the current world settings
        Returns:
        boolean true if the position constraints were solved
      • updateSpringCoefficients

        protected void updateSpringCoefficients()
        Computes the spring coefficients from the current state of the joint.

        This method is intended to set the springStiffness OR springFrequency and damping for use during constraint solving.

      • getAnchor

        public Vector2 getAnchor()
        Returns the anchor point on the body in world space.
        Returns:
        Vector2
      • 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
      • getReactionForce

        public Vector2 getReactionForce​(double invdt)
        Description copied from interface: Joint
        Returns the force applied to the PhysicsBodys in order to satisfy the constraint in newtons.
        Specified by:
        getReactionForce in interface 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 interface 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
      • getCorrectionFactor

        public double getCorrectionFactor()
        Returns the correction factor.
        Returns:
        double
        Since:
        5.0.0
      • setCorrectionFactor

        public void setCorrectionFactor​(double correctionFactor)
        Sets the correction factor.

        The correction factor controls the rate at which the bodies perform the desired actions. The default is 0.3.

        A value of zero means that the bodies do not perform any action.

        Parameters:
        correctionFactor - the correction factor in the range [0, 1]
        Since:
        5.0.0
      • getMaximumCorrectionForce

        public double getMaximumCorrectionForce()
        Returns the maximum correction force this constraint will apply in newtons.
        Returns:
        double
        Since:
        5.0.0
      • setMaximumCorrectionForce

        public void setMaximumCorrectionForce​(double maximumForce)
        Sets the maximum correction force this constraint will apply in newtons.
        Parameters:
        maximumForce - the maximum force in newtons; in the range [0, ∞]
        Throws:
        IllegalArgumentException - if maxForce is less than zero
        Since:
        5.0.0
      • getCorrectionForce

        public double getCorrectionForce​(double invdt)
        Returns the correction force from the last step.
        Parameters:
        invdt - the inverse delta time
        Returns:
        double
      • setSpringDampingRatio

        public void setSpringDampingRatio​(double dampingRatio)
        Description copied from interface: LinearSpringJoint
        Sets the damping ratio.

        Larger values reduce the oscillation of the spring.

        Specified by:
        setSpringDampingRatio in interface LinearSpringJoint
        Parameters:
        dampingRatio - the damping ratio; in the range (0, 1]
      • setSpringFrequency

        public void setSpringFrequency​(double frequency)
        Description copied from interface: LinearSpringJoint
        Sets the spring frequency.

        Larger values increase the stiffness of the spring.

        Calling this method puts the spring into fixed frequency mode. In this mode, the spring stiffness is computed based on the frequency.

        Specified by:
        setSpringFrequency in interface LinearSpringJoint
        Parameters:
        frequency - the spring frequency in hz; must be greater than zero
      • setSpringStiffness

        public void setSpringStiffness​(double stiffness)
        Description copied from interface: LinearSpringJoint
        Sets the spring stiffness.

        Larger values increase the stiffness of the spring.

        Calling this method puts the spring into fixed stiffness mode. In this mode, the spring frequency is computed based on the stiffness.

        Specified by:
        setSpringStiffness in interface LinearSpringJoint
        Parameters:
        stiffness - the spring stiffness (k); must be greater than zero
      • setMaximumSpringForce

        public void setMaximumSpringForce​(double maximum)
        Description copied from interface: LinearSpringJoint
        Sets the maximum force the spring can apply.
        Specified by:
        setMaximumSpringForce in interface LinearSpringJoint
        Parameters:
        maximum - the maximum force
      • setMaximumSpringForceEnabled

        public void setMaximumSpringForceEnabled​(boolean enabled)
        Description copied from interface: LinearSpringJoint
        Sets whether the spring force is limited to the maximum.
        Specified by:
        setMaximumSpringForceEnabled in interface LinearSpringJoint
        Parameters:
        enabled - true if the spring force should be limited
      • setSpringEnabled

        public void setSpringEnabled​(boolean enabled)
        Description copied from interface: LinearSpringJoint
        Sets whether the spring is enabled or not.
        Specified by:
        setSpringEnabled in interface LinearSpringJoint
        Parameters:
        enabled - true if the spring should be enabled
      • getSpringForce

        public double getSpringForce​(double invdt)
        Description copied from interface: LinearSpringJoint
        Returns the force in netwons applied by the spring in the last timestep.
        Specified by:
        getSpringForce in interface LinearSpringJoint
        Parameters:
        invdt - the inverse delta time
        Returns:
        double