Module org.dyn4j

Class Mass

  • All Implemented Interfaces:
    Copyable<Mass>

    public class Mass
    extends Object
    implements Copyable<Mass>
    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:
    5.0.0
    Author:
    William Bittle
    See Also:
    MassType
    • 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:
        NullPointerException - if center is null
        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:
        NullPointerException - if mass is null
    • Method Detail

      • copy

        public Mass copy()
        Description copied from interface: Copyable
        Returns a deep copy of this object.
        Specified by:
        copy in interface Copyable<Mass>
        Returns:
        T
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • create

        public static Mass create​(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:
        NullPointerException - if masses is null or contains null elements
        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.

        NOTE: This method will only set the MassType when it's valid to do so. The following logic describes this:

        Otherwise, the operation will be ignored and the current mass type left as is.
        Parameters:
        type - the mass type
        Throws:
        NullPointerException - if type is null
      • getCenter

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