Wednesday, May 25, 2011

Time stepper and physical object classes

I started writing two new classes today: TimeStepper and PhysicalObject.

The TimeStepper class is designed to take in physical objects, add them to a local list, and then update their state using their own derivative functions. TimeStepper itself is meant to be a strategy class, such that it can contain a pointer to a ConcreteTimeStepper strategy subclass which will implement a particular timestepping algorithm, aka Explicit Euler, Leap Frog, Runge Kutt 4, etc.

The physical object class is much that same as the TimeStepper in that it is a base class consisting of a state vector and methods to manipulate the state vector. For the base class, these are empty methods (accept for things common to all physical objects, such as mass). The state itself is implemented as a vector, and each type of physical object can treat this vector differently. For instance, the ParticlePhysicalObject can treat it as a 6-component vector where the first 3 are position and second 3 entries are velocity values. It also contains a vector of constant accelerations which can be used to add things such as gravity to the mix. Each physical object will contain its own GetStateDerivative vector which returns a pointer through the parameter to an array the same length of the state vector, but with each entry being the derivative of that entry in the state with respect to time. This way, timestepper doesn't need to know whether the PhysicalObject is a particle, a rigid body, or a deformable object, as long as the derivative entries from this function correspond to the same entries in its state, then TimeStepper can use the derivative information to do its thing without a care in the world.

For TimeStepper, I'm thinking about just maintaining a vector of PhysicalObject pointers which can be registered the the TimeStepper.

In the works also is a Collider with it's own strategy. I have found that the strategy pattern is translating very well to these physically based simulations.

TODO - Reread Witkin's course notes on rigid bodies.

No comments:

Post a Comment