Why simulate?

Let’s define simulation as a prediction of real-world events (think of something you cannot or don’t want to measure or something you’d like to explore before actually building it). So why bother when there’s already reality to look at?

Here are a few reasons I can come up with:

  1. We want something that feels like reality (special effects in a movie or a physics engine in a video game)
  2. We want to test a physical system before actually building it (e.g. design simulations in engineering)
  3. There’s something we’d like to know we cannot easily measure (think of the inside of reactors and high-power turbines – or complex systems like sociology or medicine where we try to infer on hidden variables to estimate treatment effects)
  4. We’d like to understand something about reality and do so by building a model of it.

The last point above is a little bit obscure and I’d like to elaborate. Actually, this is my favorite reason for spending free time with simulation (in contrast to paid time at work which is all about 1-3): I’d like to learn something about reality!

Continue reading


The difference between torque and force

I remember when I was a first-year student, I had a hard time figuring out what exactly torque is. My first year of mechanics was all about static calculations and I feel torque is just so much easier to explain when you’re considering a dynamic system.

So let’s try this: Consider a body floating in free space with rocket boosters attached to it.

Force: If a rocket fires, it will exhibit a force on the body. This will make the body move (accleration = force / mass ).

The yellow rocket fires, this makes the body move to the left

Torque: If two rockets fire in opposite directions, the force will cancel out. Depending on their positions relative to each other, a torque will however be created. This will make the body rotate (rotational acceleration = torque / inertia).

Orange and red rockets fire (on the already moving body). Forces cancel out, but the body starts to rotate.

Continue reading

Bringing objects to my Processing simulation

Two years ago I’ve written a post on building an object-oriented multibody structure in Matlab. The project has since been sleeping, but since my experiments with Processing I decided to implement a comparable structure there. This means:

  • A structure that is hopefully easy to expand and modify
  • Code that is running in Java (with the possibility to port it to C++ / Arduino) that should be reasonably fast.
  • A slightly modified approach compared to my original Matlab implementation (in some cases with clear improvements)

This approach allows a very elegant interface for simulation: Adding an object is just one line of code, as is simulating one timestep:


Continue reading

Interactive multibody dynamics in Processing

Processing is a programming language / IDE built on top of Java that’s intended for simple and visual programming, making it a great tool for WYSIWYS (what you see is what you simulate, actually that is not a real term, I just made it up).

If you’re unsure what Processing is, you might want to check out either the examples on processing.org or the double-pendulum I’ve just built into it. It is a port of my code for Arduino with TFT, but with Processing, it’s cleaner and way nicer to play with!


You can find an interactive version of my program here on openprocessing.org. It also includes a general implementation of the Runge-Kutta algorithm for solving ODEs, in case this is needed (without giving any guarantee of correctness or code quality – use on your own risk).

Update 2018-02-11: I’ve just published an updated version that simulates three pendulums in parallel with different algorithms (explicit euler, symplectic euler and runge-kutta). You can find it here.

Real-time simulations on an Arduino (double pendulum)

I got a small display compatible with my Due for christmas. And since I really wanted to see some arduino-in-the-loop simulations, I decided to use it for exactly this: real-time multibody simulations on the Ardunio and the results displayed on the tft.

Continue reading

Impulse-based dynamics: A simple and fast way to simulate contacts and constraints

So far, I’ve mostly been working on rotational mechanics – multibody models where each mass only has one rotational degree of freedom and two state variables (angle and angular velocity). Every now and then, I use some commercially available tools to simulate more complex 2d and 3d models – often being surprised by how slow simulation is. At the same time, I’ve been wondering a lot:

  • how I’d actually model these problems by hand – especially when additional boundary conditions and/or contacts are involved.
  • why some video games seem to be able to include complex dynamics with detailed contact and collisions involved, simulating in real time (while commercial multibody simulation often takes hours to calculate a few seconds of dynamic behavior).

An important answer to these questions is the topic of impulse-based dynamics. I stumbled upon it in some amazing literature from Prof. Jan Bender (see http://www.interactive-graphics.de/) and so far I’ve been experimenting a bit with the method myself. This post today features a small and practical introduction to modelling boundary conditions in impulse-based mechanics.

Continue reading