Getting Started with Basic Simulations

One of the first things I simulated on a computer was the venerable wave equation, which is sometimes used to cheat the appearance of extremely shallow pools of water. It is a simple method for capturing an interesting phenomena, and so I created two videos which explain some of the essential “theory” behind how it is simulated and how to actually code that procedure.

Code on GitHub


7 thoughts on “Getting Started with Basic Simulations”

  1. Great stuff! I’ve also did some 2D water – in opengl using shaders plus normal mapping…. but I need to upgrade my water computation algorithm. So I probably will use your tutorial for a reference!

    1. Sounds great :) I’m glad this is meaningful to at least one person. I plan on doing a follow up showing some nicer visualization. I am going to be juggling that with several other series of videos that I am working on.

      Let me know how I can improve these.

  2. I recommend trying – if you haven’t – simulating the wave equation in a 2D spring mesh network. I had some stability problems that I couldn’t resolve even after searching the internet for an answer. Nothing I could find mentioned a formula that deviated from the standard. In the end I had to rely on my own intuition to tease a finite difference formula that was stable. I am curious if you would have the same difficulties.

    1. Spring mesh networks can be useful for creating some interesting effects, but in general, springs are difficult to keep stable because the associated linear system’s stability decreases linearly with the spring constant. So, if you tried to create a spring mesh with high stiffness, you are going to have a hard time with stability when using a simple time integration scheme. There are different integration methods, like the so-called “implicit” methods which maintain better stability (in some cases they will never become unstable). If you’re interested, I suggest you look into “implicit time integration”.

      1. Thanks for the information. I never considered implicit as I never knew about it and only wanted a real-time effect not a true simulation. Like yourself I coded it in Javascript and used the html canvas. Thus the formula I aimed for needed to be as light on arithmetic operators as possible. As you would guess that means: homogeneous network and coefficients set to one – if possible. As for the effect itself, it was fairly boring. After a few iterations the mesh simply acted like squares of wobbly jelly.
        Something else I did was use WebGL to simulate waves on the surface of a 3D object. Maybe that is something to demonstrate in your series.

Leave a Reply

Your email address will not be published. Required fields are marked *