Module org.dyn4j

Class WheelJoint<T extends PhysicsBody>

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

    public class WheelJoint<T extends PhysicsBody>
    extends Joint<T>
    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.

    The joint also supports upper and lower limits. The limits represent the maximum displacement from the anchor point along the given axis.

    Since:
    3.0.0
    Version:
    4.0.0
    Author:
    William Bittle
    See Also:
    Documentation
    • 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)
        Description copied from class: Joint
        Returns the torque applied to the PhysicsBodys in order to satisfy the constraint in newton-meters.
        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
      • 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

        @Deprecated
        public boolean isSpring()
        Deprecated.
        Deprecated in 4.0.0. Use the isSpringEnabled() method instead.
        Returns true if this wheel joint is a spring wheel joint.

        Since the frequency cannot be less than or equal to zero, this should always returne true.

        Returns:
        boolean
      • isSpringDamper

        @Deprecated
        public boolean isSpringDamper()
        Deprecated.
        Deprecated in 4.0.0. Use the isSpringDamperEnabled() method instead.
        Returns true if this wheel joint is a spring wheel joint with damping.
        Returns:
        boolean
      • isSpringEnabled

        public boolean isSpringEnabled()
        Returns true if this distance joint is a spring distance joint.
        Returns:
        boolean
        Since:
        4.0.0
      • isSpringDamperEnabled

        public boolean isSpringDamperEnabled()
        Returns true if this distance joint is a spring distance joint with damping.
        Returns:
        boolean
        Since:
        4.0.0
      • 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:
        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:
        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:
        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
      • isLimitEnabled

        public boolean isLimitEnabled()
        Returns true if the limit is enabled.
        Returns:
        boolean
      • setLimitEnabled

        public void setLimitEnabled​(boolean flag)
        Enables or disables the limit.
        Parameters:
        flag - true if the limit should be enabled
      • getUpperLimit

        public double getUpperLimit()
        Returns the upper limit in meters.
        Returns:
        double
      • setUpperLimit

        public void setUpperLimit​(double upperLimit)
        Sets the upper limit.

        Must be greater than or equal to the current lower limit.

        Parameters:
        upperLimit - the upper limit in meters
        Throws:
        IllegalArgumentException - if upperLimit is less than the current lower limit
      • getLowerLimit

        public double getLowerLimit()
        Returns the lower limit in meters.
        Returns:
        double
      • setLowerLimit

        public void setLowerLimit​(double lowerLimit)
        Sets the lower limit.

        Must be less than or equal to the current upper limit.

        Parameters:
        lowerLimit - the lower limit in meters
        Throws:
        IllegalArgumentException - if lowerLimit is greater than the current upper limit
      • setLimits

        public void setLimits​(double lowerLimit,
                              double upperLimit)
        Sets the upper and lower limits.

        The lower limit must be less than or equal to the upper limit.

        Parameters:
        lowerLimit - the lower limit in meters
        upperLimit - the upper limit in meters
        Throws:
        IllegalArgumentException - if the lowerLimit is greater than upperLimit
      • getAxis

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