Class myphysicslab.lab.engine2D.RigidBodySim
Provided By  

Extends  
All Implemented Interfaces  
All Known Direct Subclasses 
Simulation of rigid body movement with external forces like gravity or springs, but
no collisions or contact forces. RigidBodys will pass thru each other unless you use the
myphysicslab.lab.engine2D.ImpulseSim
subclass.
The AdvanceStrategy tells the DiffEqSolver to advance the simulation. The DiffEqSolver
advances the simulation by calling RigidBodySim.evaluate()
to calculate rates of
change in each of the simulation variables. The DiffEqSolver then uses an algorithm like
RungeKutta to integrate forward over a small time step to reach the new simulation
state. Within evaluate()
, the forces operate by modifying the rate of change of each
variable.
See explanations at 2D Physics Engine Overview.
RigidBodys
RigidBodySim maintains a list of myphysicslab.lab.engine2D.RigidBody
s which are
currently part of the simulation. RigidBodys can be added or removed while the
simulation is running. Each RigidBody is added to the SimList (or
removed when the RigidBody is removed).
ForceLaws
RigidBodySim maintains a list of myphysicslab.lab.model.ForceLaw
s which are each
given an opportunity to apply their force to RigidBodys during evaluate()
. Some
ForceLaws such as myphysicslab.lab.model.GravityLaw
and
myphysicslab.lab.model.DampingLaw
are set up so that they observe the SimList and
can therefore apply their force to every RigidBody.
Variables
Variables are stored in a myphysicslab.lab.model.VarsList
. Each RigidBody gets
a set of six contiguous variables that describe its current position, angle, and
velocity. The variables are laid out as follows:
x
horizontal world coords position of center of massx'
horizontal velocity of center of mass. AKAvx
y
vertical world coords position of center of massy'
vertical velocity of center of mass. AKAvy
w
angle of rotation from body coordinates in radians with positive rotation being counterclockwise. Calledw
, becausew
looks like the greek letter ω (omega) which is sometimes used for angles in math.w'
angular velocity. AKAvw
.
The starting index of a RigidBody's variables is given by RigidBody.getVarsIndex()
. To
find a particular variable, add the appropriate offset: RigidBodySim.X_, RigidBodySim.VX_, RigidBodySim.Y_, RigidBodySim.VY_, RigidBodySim.W_, RigidBodySim.VW_
.
For example, to find the angular velocity of a RigidBody:
var idx = body.getVarsIndex();
return vars[idx + RigidBodySim.VW_];
Variables at the beginning of the VariablesList:
 time
 kinetic energy
 potential energy
 total energy
The set of RigidBodys can change over time via #addBody
and #removeBody
.
Therefore the set of variables can change accordingly. Removing a RigidBody results in
its 6 variables each being marked with the reserved name 'deleted' and those slots in
the VarsList are then available for later reuse. Adding a RigidBody either extends the
length of the VarsList or reuses some previously deleted slots of variables. But the 6
variables allocated for a RigidBody are guaranteed to be contiguous.
ExpressionVariables
or
FunctionVariables
can be added to a VarsList.
Their position in the VarsList remains constant after they are allocated.
Parameters Created
 ParameterBoolean named
RigidBodySim.en.SHOW_FORCES
see#setShowForces
new RigidBodySim( opt_name )
Parameters 

