Module org.dyn4j

Class PrismaticJoint<T extends PhysicsBody>

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

    public class PrismaticJoint<T extends PhysicsBody>
    extends Joint<T>
    implements Shiftable, DataContainer
    Implementation of a prismatic joint.

    A prismatic joint constrains the linear motion of two bodies along an axis and prevents relative rotation. The whole system can rotate and translate freely.

    The initial relative rotation of the bodies will remain unchanged unless updated by calling setReferenceAngle(double) method. The bodies are not required to be aligned in any particular way.

    The world space anchor point can be any point but is typically a point on the axis of allowed motion, usually the world center of either of the joined bodies.

    The limits are linear limits along the axis. The limits are checked against the separation of the local anchor points, rather than the separation of the bodies. This can have the effect of offsetting the limit values. The best way to describe the effect is to examine the "0 to 0" limit case. This case specifies that the bodies should not move along the axis, forcing them to stay at their initial location along the axis. So if the bodies were initially separated when they were joined, they will stay separated at that initial distance.

    This joint also supports a motor. The motor is a linear motor along the axis. The motor speed can be positive or negative to indicate motion along or opposite the axis direction. The maximum motor force must be greater than zero for the motor to apply any motion.

    Since:
    1.0.0
    Version:
    4.0.0
    Author:
    William Bittle
    See Also:
    Documentation, Prismatic Constraint
    • 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

        public double getJointSpeed()
        Returns the current joint speed.
        Returns:
        double
      • getJointTranslation

        public double getJointTranslation()
        Returns the current joint translation.
        Returns:
        double
      • 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 meters / second.
        Returns:
        double
      • setMotorSpeed

        public void setMotorSpeed​(double motorSpeed)
        Sets the target motor speed.
        Parameters:
        motorSpeed - the target motor speed in meters / second
        See Also:
        setMaximumMotorForce(double)
      • getMaximumMotorForce

        public double getMaximumMotorForce()
        Returns the maximum force the motor can apply to the joint to achieve the target speed.
        Returns:
        double
      • setMaximumMotorForce

        public void setMaximumMotorForce​(double maximumMotorForce)
        Sets the maximum force the motor can apply to the joint to achieve the target speed.
        Parameters:
        maximumMotorForce - the maximum force in newtons; must be greater than zero
        Throws:
        IllegalArgumentException - if maxMotorForce is less than zero
        See Also:
        setMotorSpeed(double)
      • getMotorForce

        public double getMotorForce​(double invdt)
        Returns the applied motor force.
        Parameters:
        invdt - the inverse delta time
        Returns:
        double
      • isLimitEnabled

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

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

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

        public void setLowerLimit​(double lowerLimit)
        Sets the lower limit.
        Parameters:
        lowerLimit - the lower limit in meters
        Throws:
        IllegalArgumentException - if lowerLimit is greater than the current upper limit
      • getUpperLimit

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

        public void setUpperLimit​(double upperLimit)
        Sets the upper limit.
        Parameters:
        upperLimit - the upper limit in meters
        Throws:
        IllegalArgumentException - if upperLimit is less than the current lower 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 lowerLimit is greater than upperLimit
      • setLimitsEnabled

        public void setLimitsEnabled​(double lowerLimit,
                                     double upperLimit)
        Sets the upper and lower limits and enables the 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 lowerLimit is greater than upperLimit
        Since:
        2.2.2
      • getAxis

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

        public double getReferenceAngle()
        Returns the reference angle.

        The reference angle is the angle calculated when the joint was created from the two joined bodies. The reference angle is the angular difference between the bodies.

        Returns:
        double
        Since:
        3.0.1
      • setReferenceAngle

        public void setReferenceAngle​(double angle)
        Sets the reference angle.

        This method can be used to set the reference angle to override the computed reference angle from the constructor. This is useful in recreating the joint from a current state.

        This can also be used to override the initial angle between the bodies.

        Parameters:
        angle - the reference angle
        Since:
        3.0.1
        See Also:
        getReferenceAngle()
      • getLimitState

        @Deprecated
        public LimitState getLimitState()
        Deprecated.
        Deprecated in 4.0.0.
        Returns the current state of the limit.
        Returns:
        LimitState
        Since:
        3.2.0