Module org.dyn4j

Class AbstractJoint<T extends PhysicsBody>

    • Field Detail

      • bodies

        protected final List<T extends PhysicsBody> bodies
        An unmodifiable list of the bodies
      • collisionAllowed

        protected boolean collisionAllowed
        Whether the pair of bodies joined together can collide with each other
      • userData

        protected Object userData
        The user data
      • owner

        protected Object owner
        The joint owner
    • Constructor Detail

      • AbstractJoint

        public AbstractJoint​(List<T> bodies)
        Default constructor.
        Parameters:
        bodies - the list of bodies
        Throws:
        NullPointerException - when bodies is null or any element of bodies is null
        IllegalArgumentException - when bodies is empty
    • Method Detail

      • getFrequency

        protected static final double getFrequency​(double naturalFrequency)
        Returns the frequency given the natural frequency.

        Harmonic oscillator: f = (1 / 2π) * sqrt(k / m) Natural frequency: w = sqrt(k / m)

        Substituting w into the first equation and solving for w:

        f = (1 / 2π) * w f = w / 2π

        Parameters:
        naturalFrequency - the natural frequency
        Returns:
        double
      • getNaturalFrequency

        protected static final double getNaturalFrequency​(double frequency)
        Returns the natural frequency of the given frequency.

        The natural frequency can be determined by combining the following equations:

        Harmonic oscillator: f = 1 / (2π) * sqrt(k / m) Natural frequency: w = sqrt(k / m)

        Substituting w into the first equation and solving for w:

        f = 1 / (2π) * w w = f * 2π

        Parameters:
        frequency - the frequency
        Returns:
        double
        See Also:
        https://en.wikipedia.org/wiki/Hookes_law#Harmonic_oscillator
      • getNaturalFrequency

        protected static final double getNaturalFrequency​(double stiffness,
                                                          double mass)
        Returns the natural frequency given the spring stiffness and mass.

        Natural frequency: w = sqrt(k / m)

        Parameters:
        stiffness - the spring stiffness
        mass - the mass
        Returns:
        double
      • getSpringDampingCoefficient

        protected static final double getSpringDampingCoefficient​(double mass,
                                                                  double naturalFrequency,
                                                                  double dampingRatio)
        Returns the spring damping coefficient.

        The damping coefficient can be determined by the following equations:

        Damping Ratio: dr = actual damping (ad) / critical damping (cd) Critical Damping: cd = 2mw

        Where m is the mass and w is the natural frequency. Substituting cd into the first equation and solving for ad:

        dr = ad / 2mw ad = dr * 2mw

        Parameters:
        mass - the mass attached to the spring
        naturalFrequency - the natural frequency
        dampingRatio - the damping ratio
        Returns:
        double
        See Also:
        https://en.wikipedia.org/wiki/Damping_ratio
      • getSpringStiffness

        protected static final double getSpringStiffness​(double mass,
                                                         double naturalFrequency)
        Returns the spring stiffness, k, from Hooke's Law.

        The stiffness can be determined by the following equation and solving for k:

        Harmonic oscillator: f = 1 / (2π) * sqrt(k / m) f * 2π = sqrt(k / m) k / m = (f * 2π)2 k = (f * 2π)2 * m k = w2 * m

        Where w is the natural frequency and m is the mass.
        Parameters:
        mass - the mass attached to the spring
        naturalFrequency - the natural frequency
        Returns:
        double
        See Also:
        https://en.wikipedia.org/wiki/Hookes_law#Harmonic_oscillator
      • getConstraintImpulseMixing

        protected static final double getConstraintImpulseMixing​(double deltaTime,
                                                                 double stiffness,
                                                                 double damping)
        Returns the constraint impulse mixing parameter.
        Parameters:
        deltaTime - the time step
        stiffness - the stiffness of the spring
        damping - the damping coefficient of the spring
        Returns:
        double
        See Also:
        http://www.ode.org/ode-latest-userguide.html#sec_3_8_2
      • getErrorReductionParameter

        protected static final double getErrorReductionParameter​(double deltaTime,
                                                                 double stiffness,
                                                                 double damping)
        Returns the error reduction parameter.
        Parameters:
        deltaTime - the time step
        stiffness - the stiffness of the spring
        damping - the damping coefficient of the spring
        Returns:
        double
        See Also:
        http://www.ode.org/ode-latest-userguide.html#sec_3_8_2
      • getBodies

        public final List<T> getBodies()
        Description copied from interface: Joint
        Returns an unmodifiable list of bodies involved in this joint.
        Specified by:
        getBodies in interface Joint<T extends PhysicsBody>
        Returns:
        List<T>
      • getBodyCount

        public int getBodyCount()
        Description copied from interface: Joint
        Returns the number of bodies involved in this joint.
        Specified by:
        getBodyCount in interface Joint<T extends PhysicsBody>
        Returns:
        int
      • getBody

        public T getBody​(int index)
        Description copied from interface: Joint
        Returns the body at the given index.
        Specified by:
        getBody in interface Joint<T extends PhysicsBody>
        Parameters:
        index - the index
        Returns:
        T
      • getBodyIterator

        public final Iterator<T> getBodyIterator()
        Description copied from interface: Joint
        Returns an iterator for the bodies involved in this joint.

        NOTE: The iterator is read-only and will throw if methods like remove are used.

        Specified by:
        getBodyIterator in interface Joint<T extends PhysicsBody>
        Returns:
        Iterator<T>
      • isEnabled

        public boolean isEnabled()
        Description copied from interface: Joint
        Returns true if this Joint is enabled.

        A joint is only enabled if all joined PhysicsBodys are enabled.

        Specified by:
        isEnabled in interface Joint<T extends PhysicsBody>
        Returns:
        boolean
      • isMember

        public boolean isMember​(CollisionBody<?> body)
        Description copied from interface: Joint
        Returns true if the given body is a member of this joint.
        Specified by:
        isMember in interface Joint<T extends PhysicsBody>
        Parameters:
        body - the body
        Returns:
        boolean
      • isCollisionAllowed

        public boolean isCollisionAllowed()
        Description copied from interface: Joint
        Returns true if collision between the joined PhysicsBodys is allowed.
        Specified by:
        isCollisionAllowed in interface Joint<T extends PhysicsBody>
        Returns:
        boolean
      • setCollisionAllowed

        public void setCollisionAllowed​(boolean flag)
        Description copied from interface: Joint
        Sets whether collision is allowed between the joined PhysicsBodys.
        Specified by:
        setCollisionAllowed in interface Joint<T extends PhysicsBody>
        Parameters:
        flag - true if collisions are allowed
      • getUserData

        public Object getUserData()
        Description copied from interface: DataContainer
        Gets the custom user data.
        Specified by:
        getUserData in interface DataContainer
        Returns:
        Object will return null if not set
      • setUserData

        public void setUserData​(Object userData)
        Description copied from interface: DataContainer
        Sets the custom user data to the given data.
        Specified by:
        setUserData in interface DataContainer
        Parameters:
        userData - the user data
      • getOwner

        public Object getOwner()
        Description copied from interface: Ownable
        Returns the owner for this body.
        Specified by:
        getOwner in interface Ownable
        Returns:
        Object
      • setOwner

        public void setOwner​(Object owner)
        Description copied from interface: Ownable
        Sets the owner of this body.
        Specified by:
        setOwner in interface Ownable
        Parameters:
        owner - the owner