Packageorg.generalrelativity.foam.dynamics.element.body
Classpublic class RigidBody
InheritanceRigidBody Inheritance SimpleParticle
ImplementsIBody, IODE, ISimulatable
SubclassesCircle, CubicBezierCurve



Public Properties
 PropertyDefined by
  av : Number
RigidBody
  collisionTypeID : String
[read-only]
RigidBody
  edges : Array
[read-only]
RigidBody
 Inheritedelasticity : Number
SimpleParticle
 Inheritedforce : Vector
SimpleParticle
 Inheritedfriction : Number
SimpleParticle
  I : Number
[read-only]
RigidBody
  inverseI : Number
[read-only]
RigidBody
 InheritedinverseMass : Number
SimpleParticle
 Inheritedmass : Number
SimpleParticle
 Inheritedposition : Vector
SimpleParticle
  q : Number
RigidBody
  rotation : RotationMatrix
[read-only] Gets the rotation matrix of the body

Because the creation of a rotation matrix involves 2 trigonometric function calls, it's worthwhile to do a check to see if we need to create a new rotation matrix.

RigidBody
 Inheritedstate : Array
Gets the state of the differential equation

Consider a particle with position x and velocity v.

SimpleParticle
  torque : Number
[read-only]
RigidBody
 Inheritedvelocity : Vector
SimpleParticle
  vertices : Array
[read-only]
RigidBody
 Inheritedvx : Number
SimpleParticle
 Inheritedvy : Number
SimpleParticle
 Inheritedx : Number
Note that these values that constitute this IODE's state use getters/setters that access specific indices within _state.
SimpleParticle
 Inheritedy : Number
SimpleParticle
Protected Properties
 PropertyDefined by
  _edges : Array
body edges
RigidBody
 Inherited_elasticity : Number
elastic coefficient of particle (used in collision response)
SimpleParticle
 Inherited_force : Vector
holds all accummulate forces
SimpleParticle
 Inherited_friction : Number
frictional coefficient (used in collision response)
SimpleParticle
 Inherited_generators : Array
holds all IForceGenerators affecting this particle
SimpleParticle
  _I : Number
inertia tensor
RigidBody
  _inverseI : Number
inverse inertia tensor
RigidBody
 Inherited_inverseMass : Number
holds the inverse mass- this is an optimization as multiplication is faster than division and we can calculate this offline
SimpleParticle
 Inherited_mass : Number
holds the mass of the particle
SimpleParticle
  _rotation : RotationMatrix
rotation matrix of body
RigidBody
 Inherited_state : Array
holds the state of the system
SimpleParticle
  _torque : Number
torque accumulator
RigidBody
  _vertices : Array
body vertices
RigidBody
Public Methods
 MethodDefined by
  
RigidBody(x:Number, y:Number, mass:Number = 100, vertices:Array = null, vx:Number = 0, vy:Number = 0, friction:Number = 0.2, elasticity:Number = 0.25, q:Number = 0, av:Number = 0)
Creates a new RigidBody

This will most likely be the most used element in FOAM.

RigidBody
 Inherited
Accumulates forces
SimpleParticle
 Inherited
addForce(force:Vector):void
Adds a force to the particle
SimpleParticle
  
addForceAtPoint(point:Vector, force:Vector):void
Adds a force at a specific point on the body

IF the point specified is not the center of mass (0,0), the force will induce a change in angular velocity as well as linear.

RigidBody
 Inherited
Adds a force generator to influence this particle
SimpleParticle
  
addTorque(torque:Number):void
Adds torque to the body

This is the rotational equivalent to adding a force

RigidBody
 Inherited
clearForces():void
Clears all forces
SimpleParticle
  
clearTorque():void
Clears any accumulated torque
RigidBody
  
getDerivative(state:Array, derivative:Array):void
Gets the derivative of the body

Note that both the state and derivative are longer than in SimpleParticle.

RigidBody
  
Gets the velocity of the body at a specified point

Note that this point is given in world-coordinates.

RigidBody
 Inherited
Removes a force generator
SimpleParticle
Protected Methods
 MethodDefined by
  
Calculates the body's inertia tensor

The inertia tensor is the rotational equivalent to mass- it is also linked to mass.

RigidBody
Property detail
avproperty
av:Number  [read-write]Implementation
    public function get av():Number
    public function set av(value:Number):void
collisionTypeIDproperty 
collisionTypeID:String  [read-only]Implementation
    public function get collisionTypeID():String
_edgesproperty 
protected var _edges:Array

body edges

edgesproperty 
edges:Array  [read-only]Implementation
    public function get edges():Array
_Iproperty 
protected var _I:Number

inertia tensor

Iproperty 
I:Number  [read-only]Implementation
    public function get I():Number
_inverseIproperty 
protected var _inverseI:Number

inverse inertia tensor

inverseIproperty 
inverseI:Number  [read-only]Implementation
    public function get inverseI():Number
qproperty 
q:Number  [read-write]Implementation
    public function get q():Number
    public function set q(value:Number):void
_rotationproperty 
protected var _rotation:RotationMatrix

rotation matrix of body

rotationproperty 
rotation:RotationMatrix  [read-only]

Gets the rotation matrix of the body

Because the creation of a rotation matrix involves 2 trigonometric function calls, it's worthwhile to do a check to see if we need to create a new rotation matrix.

Implementation
    public function get rotation():RotationMatrix
_torqueproperty 
protected var _torque:Number

torque accumulator

torqueproperty 
torque:Number  [read-only]Implementation
    public function get torque():Number
_verticesproperty 
protected var _vertices:Array

body vertices

verticesproperty 
vertices:Array  [read-only]Implementation
    public function get vertices():Array
Constructor detail
RigidBody()constructor
public function RigidBody(x:Number, y:Number, mass:Number = 100, vertices:Array = null, vx:Number = 0, vy:Number = 0, friction:Number = 0.2, elasticity:Number = 0.25, q:Number = 0, av:Number = 0)

Creates a new RigidBody

This will most likely be the most used element in FOAM. It's important to note that most aspects of simulation assume convexity in bodies.

Parameters
x:Number — body's x position
 
y:Number — body's y postiion
 
mass:Number (default = 100) — body's mass
 
vertices:Array (default = null) — body vertices
 
vx:Number (default = 0) — horizontal velocity,
 
vy:Number (default = 0) — vertical velocity,
 
friction:Number (default = 0.2) — body's surface frictional coefficient
 
elasticity:Number (default = 0.25) — body's elasticity
 
q:Number (default = 0) — body's orientation (in radians)
 
av:Number (default = 0) — body's angular velocity

See also

SimpleParticle
caclculateInertiaTensor
Method detail
addForceAtPoint()method
public function addForceAtPoint(point:Vector, force:Vector):void

Adds a force at a specific point on the body

IF the point specified is not the center of mass (0,0), the force will induce a change in angular velocity as well as linear. Note that this point is given in relative coordinates to the body- that is NOT in world-coordinates.

Parameters
point:Vector — point on body relative to its center of mass on which to apply force
 
force:Vector — force to apply at point
addTorque()method 
public function addTorque(torque:Number):void

Adds torque to the body

This is the rotational equivalent to adding a force

Parameters
torque:Number — amount of torque to add
calculateInertiaTensor()method 
protected function calculateInertiaTensor():void

Calculates the body's inertia tensor

The inertia tensor is the rotational equivalent to mass- it is also linked to mass. In 3 dimensions, the inertia tensor is a 3x3 matrix- in 2 dimensions it is a rank 0 tensor, or simply, a scalar.

TODO: This is not very physically accurate, but provides decent resulsts for convex shapes. Improve.
clearTorque()method 
public function clearTorque():void

Clears any accumulated torque

getDerivative()method 
public override function getDerivative(state:Array, derivative:Array):void

Gets the derivative of the body

Note that both the state and derivative are longer than in SimpleParticle. This is because a rigid body has 2 more properties to integrate with respect to time (orientation and angular velocity).

Parameters
state:Array — body's state
 
derivative:Array — Array to populate with body's derivative

See also

IODE.getDerivative
SimpleParticle
getVelocityAtPoint()method 
public function getVelocityAtPoint(point:Vector):Vector

Gets the velocity of the body at a specified point

Note that this point is given in world-coordinates.

TODO: why is this given in world coordinates and addForceAtPoint relative? Probably confusing... Parameters
point:Vector — point to determine velocity from

Returns
Vector — componentized velocity