Module org.dyn4j

Class Mass


  • public class Mass
    extends java.lang.Object
    Represents Mass data for an object about a given point.

    Stores the center of mass, the mass, and inertia.

    The center point may be something other than the origin (0, 0). In this case, the mass and inertia are about this point, not the origin.

    A Mass can also take on special MassTypes. These mass types allow for interesting effects during interaction.

    When the mass type is changed, the original mass and inertia values are not lost. This allows the swapping of mass types without recomputing the mass.

    Since:
    1.0.0
    Version:
    3.4.0
    Author:
    William Bittle
    See Also:
    MassType
    • Field Detail

      • center

        final Vector2 center
        The center of mass
      • mass

        final double mass
        The mass in kg
      • inertia

        final double inertia
        The inertia tensor in kg · m2
      • invMass

        final double invMass
        The inverse mass
      • invInertia

        final double invInertia
        The inverse inertia tensor
    • Constructor Detail

      • Mass

        public Mass()
        Default constructor.

        Creates an infinite mass centered at the origin.

      • Mass

        public Mass​(Vector2 center,
                    double mass,
                    double inertia)
        Full Constructor.

        The center parameter will be copied.

        Parameters:
        center - center of Mass in local coordinates
        mass - mass in kg
        inertia - inertia tensor in kg · m2
        Throws:
        java.lang.NullPointerException - if center is null
        java.lang.IllegalArgumentException - if mass or inertia is less than zero
      • Mass

        public Mass​(Mass mass)
        Copy constructor.

        Performs a deep copy.

        Parameters:
        mass - the Mass to copy
        Throws:
        java.lang.NullPointerException - if mass is null
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • create

        public static Mass create​(java.util.List<Mass> masses)
        Creates a Mass object from the given array of masses.

        Uses the Parallel Axis Theorem to obtain the inertia tensor about the center of all the given masses:

        Idis = Icm + mr2 Itotal = ∑ Idis

        The center for the resulting mass will be a mass weighted center.

        This method will produce unexpected results if any mass contained in the list is infinite.

        Parameters:
        masses - the list of Mass objects to combine
        Returns:
        Mass the combined Mass
        Throws:
        java.lang.NullPointerException - if masses is null or contains null elements
        java.lang.IllegalArgumentException - if masses is empty
      • isInfinite

        public boolean isInfinite()
        Returns true if this Mass object is of type MassType.INFINITE.

        A mass will still be treated as an infinite mass in physical modeling if the mass and inertia are zero. This method simply checks the mass type.

        Returns:
        boolean
      • setType

        public void setType​(MassType type)
        Sets the mass type.
        Parameters:
        type - the mass type
        Throws:
        java.lang.NullPointerException - if type is null
      • getCenter

        public Vector2 getCenter()
        Returns the center of mass.
        Returns:
        Vector2
      • getMass

        public double getMass()
        Returns the mass.
        Returns:
        double
      • getInertia

        public double getInertia()
        Returns the inertia tensor.
        Returns:
        double
      • getInverseMass

        public double getInverseMass()
        Returns the inverse mass.
        Returns:
        double
      • getInverseInertia

        public double getInverseInertia()
        Returns the inverse inertia tensor.
        Returns:
        double