- Object
-
- AbstractJoint<T>
-
- Type Parameters:
T
- thePhysicsBody
type
- All Implemented Interfaces:
DataContainer
,Joint<T>
,Shiftable
,Ownable
- Direct Known Subclasses:
AbstractPairedBodyJoint
,AbstractSingleBodyJoint
public abstract class AbstractJoint<T extends PhysicsBody> extends Object implements Joint<T>, Shiftable, DataContainer, Ownable
Represents an abstract implementation of constrained motion betweenPhysicsBody
s.- Since:
- 5.0.0
- Version:
- 5.0.0
- Author:
- William Bittle
-
-
Field Summary
Fields Modifier and Type Field Description protected List<T>
bodies
An unmodifiable list of the bodiesprotected boolean
collisionAllowed
Whether the pair of bodies joined together can collide with each otherprotected Object
owner
The joint ownerprotected Object
userData
The user data-
Fields inherited from interface Joint
SPRING_MODE_FREQUENCY, SPRING_MODE_STIFFNESS
-
-
Constructor Summary
Constructors Constructor Description AbstractJoint(List<T> bodies)
Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<T>
getBodies()
Returns an unmodifiable list of bodies involved in this joint.T
getBody(int index)
Returns the body at the given index.int
getBodyCount()
Returns the number of bodies involved in this joint.Iterator<T>
getBodyIterator()
Returns an iterator for the bodies involved in this joint.protected static double
getConstraintImpulseMixing(double deltaTime, double stiffness, double damping)
Returns the constraint impulse mixing parameter.protected static double
getErrorReductionParameter(double deltaTime, double stiffness, double damping)
Returns the error reduction parameter.protected static double
getFrequency(double naturalFrequency)
Returns the frequency given the natural frequency.protected static double
getNaturalFrequency(double frequency)
Returns the natural frequency of the given frequency.protected static double
getNaturalFrequency(double stiffness, double mass)
Returns the natural frequency given the spring stiffness and mass.Object
getOwner()
Returns the owner for this body.protected static double
getSpringDampingCoefficient(double mass, double naturalFrequency, double dampingRatio)
Returns the spring damping coefficient.protected static double
getSpringStiffness(double mass, double naturalFrequency)
Returns the spring stiffness, k, from Hooke's Law.Object
getUserData()
Gets the custom user data.boolean
isCollisionAllowed()
Returns true if collision between the joinedPhysicsBody
s is allowed.boolean
isEnabled()
Returns true if thisJoint
is enabled.boolean
isMember(CollisionBody<?> body)
Returns true if the given body is a member of this joint.void
setCollisionAllowed(boolean flag)
Sets whether collision is allowed between the joinedPhysicsBody
s.void
setOwner(Object owner)
Sets the owner of this body.void
setUserData(Object userData)
Sets the custom user data to the given data.String
toString()
-
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface Joint
getReactionForce, getReactionTorque, initializeConstraints, solvePositionConstraints, solveVelocityConstraints
-
-
-
-
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 nullIllegalArgumentException
- 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 stiffnessmass
- 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 springnaturalFrequency
- the natural frequencydampingRatio
- 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 springnaturalFrequency
- 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 stepstiffness
- the stiffness of the springdamping
- 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 stepstiffness
- the stiffness of the springdamping
- 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 interfaceJoint<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 interfaceJoint<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 interfaceJoint<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 interfaceJoint<T extends PhysicsBody>
- Returns:
- Iterator<T>
-
isEnabled
public boolean isEnabled()
Description copied from interface:Joint
Returns true if thisJoint
is enabled.A joint is only enabled if all joined
PhysicsBody
s are enabled.- Specified by:
isEnabled
in interfaceJoint<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 interfaceJoint<T extends PhysicsBody>
- Parameters:
body
- the body- Returns:
- boolean
-
isCollisionAllowed
public boolean isCollisionAllowed()
Description copied from interface:Joint
Returns true if collision between the joinedPhysicsBody
s is allowed.- Specified by:
isCollisionAllowed
in interfaceJoint<T extends PhysicsBody>
- Returns:
- boolean
-
setCollisionAllowed
public void setCollisionAllowed(boolean flag)
Description copied from interface:Joint
Sets whether collision is allowed between the joinedPhysicsBody
s.- Specified by:
setCollisionAllowed
in interfaceJoint<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 interfaceDataContainer
- 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 interfaceDataContainer
- Parameters:
userData
- the user data
-
getOwner
public Object getOwner()
Description copied from interface:Ownable
Returns the owner for this body.
-
-