site logo
LIAM AXON

Water Box

Jun 20, 2021
tags: gadget, coding, simulation, threejs

This is my first attempt at simulating water. I like how it turned out, and there will certainly be more water simulations in the future, using different approaches. The physics and state of the world can be manipulated from the settings menu, and the ball can be pushed by clicking (or touching) it. This is the most computationally intensive project on this site to date, so may give performance issues. If you are having performance issues, you should try lowering the number of water particles, turning off surface tension, and turning off "dynamic water". Other options you could try are: increasing the time step, decreasing the number of constraint passes, or decreasing the speed.

I used the same technique here as in my past two physics simulations (Ball and String and Blanketball) called the Jakobsen Method. This method involves simulating forces, and then repeatedly enforcing constraints. To simulate forces, I used Verlet integration. You can read more about this method in those past project descriptions. The water is simulated as a sea of particles which have their individual positions and velocities.

The objects in this experiment experience up to four forces: gravity, surface tension, drag (linear with velocity), and the normal force (simulated as constraints). Each of these forces can be tweaked during the simulation for interesting results. Interactions between water particles grow quadratically in the number of water molecules, and was the primary bottleneck when creating this simulation. To reduce computation times, the world is sectioned into "chunks", where water particles in one chunk can only interact with those in nearby chunks.

Click here to open the gadget.

screenshot of gadget