- Object
-
- Mass
-
public class Mass extends Object implements Copyable<Mass>
RepresentsMass
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 specialMassType
s. 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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Mass
copy()
Returns a deep copy of this object.static Mass
create(List<Mass> masses)
Creates aMass
object from the given array of masses.boolean
equals(Object other)
Vector2
getCenter()
Returns the center of mass.double
getInertia()
Returns the inertia tensor.double
getInverseInertia()
Returns the inverse inertia tensor.double
getInverseMass()
Returns the inverse mass.double
getMass()
Returns the mass.MassType
getType()
Returns the mass type.int
hashCode()
boolean
isInfinite()
Returns true if thisMass
object is of typeMassType.INFINITE
.void
setType(MassType type)
Sets the mass type.String
toString()
-
-
-
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 ofMass
in local coordinatesmass
- mass in kginertia
- inertia tensor in kg · m2- Throws:
NullPointerException
- if center is nullIllegalArgumentException
- if mass or inertia is less than zero
-
Mass
public Mass(Mass mass)
Copy constructor.Performs a deep copy.
- Parameters:
mass
- theMass
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.
-
create
public static Mass create(List<Mass> masses)
Creates aMass
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 ofMass
objects to combine- Returns:
Mass
the combinedMass
- Throws:
NullPointerException
- if masses is null or contains null elementsIllegalArgumentException
- if masses is empty
-
isInfinite
public boolean isInfinite()
Returns true if thisMass
object is of typeMassType.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:
- The given type is
MassType.NORMAL
and both the mass and inertia are non-zero - The given type is
MassType.FIXED_LINEAR_VELOCITY
and inertia is non-zero - The given type is
MassType.FIXED_ANGULAR_VELOCITY
and the mass is non-zero
- Parameters:
type
- the mass type- Throws:
NullPointerException
- if type is null
- The given type is
-
getMass
public double getMass()
Returns the mass.NOTE: if this mass is type
MassType.INFINITE
orMassType.FIXED_LINEAR_VELOCITY
this method returns zero.- Returns:
- double
-
getInertia
public double getInertia()
Returns the inertia tensor.NOTE: if this mass is type
MassType.INFINITE
orMassType.FIXED_ANGULAR_VELOCITY
this method returns zero.- Returns:
- double
-
getInverseMass
public double getInverseMass()
Returns the inverse mass.NOTE: if this mass is type
MassType.INFINITE
orMassType.FIXED_LINEAR_VELOCITY
this method returns zero.- Returns:
- double
-
getInverseInertia
public double getInverseInertia()
Returns the inverse inertia tensor.NOTE: if this mass is type
MassType.INFINITE
orMassType.FIXED_ANGULAR_VELOCITY
this method returns zero.- Returns:
- double
-
-