search

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 sub-class.

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 Runge-Kutta 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.RigidBodys 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.ForceLaws 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:

  1. x horizontal world coords position of center of mass
  2. x' horizontal velocity of center of mass. AKA vx
  3. y vertical world coords position of center of mass
  4. y' vertical velocity of center of mass. AKA vy
  5. w angle of rotation from body coordinates in radians with positive rotation being counter-clockwise. Called w, because w looks like the greek letter ω (omega) which is sometimes used for angles in math.
  6. w' angular velocity. AKA vw.

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

new RigidBodySim( opt_name )

Parameters
opt_name(string|undefined)

name of this Subject

Instance Methods

Instance Properties

Static Properties

Type Definitions