Skip to content
Alessandro Solbiati

Building a Physics Engine

physics, programming, ClojureScript1 min read

I got my hands on Landau, Course of Theoretical Physics. I want to challenge my understanding of the book by writing a physics engine that provide a computational layer for the book chapter by chapter.

Just another Physics Engine

Out there you can find any sort of stuff if you are interested in physics engines, from general computation frameworks like Mathematica to game engines like Unreal. A good textbook on physics engines is Structure and Interpretation of Classical Mechanics, an unusual physics textbook that approach the subject from computational perspective.

Even if originally I had the idea of building the Physics Engine in Lisp, I wanted to build something that works in the web, so I eventually turned my attention to Javascript. three.js looks like a good starting point for the 3d rendering part, and turns out it works also in virtual reality: I managed to build an immersive 3d website in a couple of hour that run on my Oculus Quest.

Fluid Simulation

I will be start with the hard part of implementing Navier-Stokes equation, following the paper Real Time Fluid Dynamics for Game, Stam 2003.

I implemented it in ClojureScripts and so far got pretty recent results, you can find it at https://github.com/SolbiatiAlessandro/steamengine. I named it steamengine since I want to try to simulate the fluid-dynamics physical process of steam engines. Here are three examples of what you can do with the implementation of that paper:

  1. https://youtube.com/d7r9XxQVUjM 3D diffusion of water in a box (from a Oculus Quest 1 browser)

IMAGE ALT TEXT HERE

  1. https://youtu.be/LBo67lY-p7E 2D diffusion of water under static diagonal velocity field in a box (from Laptop browser)

IMAGE ALT TEXT HERE

  1. https://youtu.be/eVWq8RlS6tc 2d diffusion of water (from Laptop browser)

IMAGE ALT TEXT HERE