Module org.dyn4j

Class WheelJoint

  • All Implemented Interfaces:
    DataContainer, Shiftable

    public class WheelJoint
    extends Joint
    implements Shiftable, DataContainer
    Implementation of a wheel joint.

    A wheel joint is used to simulate a vehicle's wheel and suspension. The wheel is allowed to rotate freely about the given anchor point. The suspension is allowed to translate freely along the given axis. The whole system can translate and rotate freely.

    By default the frequency and damping ratio are set to 8.0 and 0.0 respectively. By definition this joint requires a frequency greater than zero to perform properly. If a wheel without suspension is required, use a RevoluteJoint instead.

    This joint also supports a motor. The motor is an angular motor about the anchor point. The motor speed can be positive or negative to indicate a clockwise or counter-clockwise rotation. The maximum motor torque must be greater than zero for the motor to apply any motion.

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

      • localAnchor1

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

        protected Vector2 localAnchor2
        The local anchor point on the second Body
      • motorEnabled

        protected boolean motorEnabled
        Whether the motor is enabled or not
      • motorSpeed

        protected double motorSpeed
        The target velocity in radians / second
      • maximumMotorTorque

        protected double maximumMotorTorque
        The maximum torque the motor can apply in newton-meters
      • frequency

        protected double frequency
        The oscillation frequency in hz
      • dampingRatio

        protected double dampingRatio
        The damping ratio
    • Constructor Detail

      • WheelJoint

        public WheelJoint​(Body body1,
                          Body body2,
                          Vector2 anchor,
                          Vector2 axis)
        Minimal constructor.
        Parameters:
        body1 - the first Body
        body2 - the second Body
        anchor - the anchor point in world coordinates
        axis - the axis of allowed motion
        Throws:
        java.lang.NullPointerException - if body1, body2, anchor, or axis 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)
        Description copied from class: Joint
        Returns the torque applied to the Bodys in order to satisfy the constraint in newton-meters.
        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
      • getJointSpeed

        @Deprecated
        public double getJointSpeed()
        Deprecated.
        Replaced by getAngularSpeed() in 3.2.1
        Returns the current joint speed.
        Returns:
        double
      • getLinearSpeed

        public double getLinearSpeed()
        Returns the linear speed along the axis between the two joined bodies
        Returns:
        double
        Since:
        3.2.1
      • getAngularSpeed

        public double getAngularSpeed()
        Returns the current angular speed between the two joined bodies.
        Returns:
        double
        Since:
        3.2.1
      • getJointTranslation

        @Deprecated
        public double getJointTranslation()
        Deprecated.
        Replaced by getLinearTranslation() in 3.2.1
        Returns the current joint translation.
        Returns:
        double
      • getLinearTranslation

        public double getLinearTranslation()
        Returns the current linear translation along the joint axis.
        Returns:
        double
        Since:
        3.2.1
      • getAngularTranslation

        public double getAngularTranslation()
        Returns the current angular translation between the joined bodies.
        Returns:
        double
        Since:
        3.2.1
      • isSpring

        public boolean isSpring()
        Returns true if this wheel joint is a spring wheel joint.
        Returns:
        boolean
      • isSpringDamper

        public boolean isSpringDamper()
        Returns true if this wheel joint is a spring wheel joint with damping.
        Returns:
        boolean
      • getDampingRatio

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

        public void setDampingRatio​(double dampingRatio)
        Sets the damping ratio.

        Larger values reduce the oscillation of the spring.

        Parameters:
        dampingRatio - the damping ratio; in the range [0, 1]
        Throws:
        java.lang.IllegalArgumentException - if damping ration is less than zero or greater than 1
      • getFrequency

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

        public void setFrequency​(double frequency)
        Sets the spring frequency.

        Larger values increase the stiffness of the spring.

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

        public boolean isMotorEnabled()
        Returns true if the motor is enabled.
        Returns:
        boolean
      • setMotorEnabled

        public void setMotorEnabled​(boolean motorEnabled)
        Enables or disables the motor.
        Parameters:
        motorEnabled - true if the motor should be enabled
      • getMotorSpeed

        public double getMotorSpeed()
        Returns the target motor speed in radians / second.
        Returns:
        double
      • setMotorSpeed

        public void setMotorSpeed​(double motorSpeed)
        Sets the target motor speed.
        Parameters:
        motorSpeed - the target motor speed in radians / second
        See Also:
        setMaximumMotorTorque(double)
      • getMaximumMotorTorque

        public double getMaximumMotorTorque()
        Returns the maximum torque the motor can apply to the joint to achieve the target speed.
        Returns:
        double
      • setMaximumMotorTorque

        public void setMaximumMotorTorque​(double maximumMotorTorque)
        Sets the maximum torque the motor can apply to the joint to achieve the target speed.
        Parameters:
        maximumMotorTorque - the maximum torque in newtons-meters; in the range [0, ∞]
        Throws:
        java.lang.IllegalArgumentException - if maxMotorTorque is less than zero
        See Also:
        setMotorSpeed(double)
      • getMotorTorque

        public double getMotorTorque​(double invdt)
        Returns the applied motor torque.
        Parameters:
        invdt - the inverse delta time from the time step
        Returns:
        double
      • getAxis

        public Vector2 getAxis()
        Returns the axis in which the joint is allowed move along in world coordinates.
        Returns:
        Vector2