Monday, December 3, 2007

grids

look around you. grids are everywhere! and the most exciting thing is... it can make fluid simulations faster (or other particle simulations where particles collide with each other)! and i will show you how.

so you've just implemented your first fluid dynamics solver, and it seems pretty slow. (if you haven't yet, you may want to google smoothed particle hydrodynamics or fluid simulations) and the worst thing is, when you simulate 2000 particles, it won't be even half as fast as 1000 particles. the thing is, you're currently in the realm of O(n^2). that means the time it takes to simulate n particles is proportional to n^2. what grids can do is make it O(n).

i bet you're really curious now, so let's go deeper. see, the main problem of simulating thousands of circles that collide with each other is, you can't tell right away if two of them are colliding. you have to use a distance formula, and all those extra calculations really slow the computer down. grids help lessen those calculations.