Purely functional 3D physics engine