What’s better suited for object-oriented programming (OOP) than building a simulation of a physical system? Each physical object (e.g. mass, spring etc.) can be implemented as an object and then we should be able to easily build and modify large models.
However, there are a lot of challenges to get there, including:
- How to work with classes and objects at all (if you’re like me new to OOP)?
- How to build a working object structure that adopts to the requirements of a typical ODE solver (which usually requires access to all state variables in the so-called state-space representation)
- How to design classes for different object types in a way that allows them interact with each other to calculate and transmit forces and accelerations.
Getting there turned out to be quite interesting and I finally got a simple object-oriented multibody model to simulate in Matlab and GNU Octave. This post is a wrapup of all the stuff I learned to get there.
Update: There is now also a newer post I’ve just written on a comparable multibody simulation structure in Processing / Java.