Diffusion Limited Aggregation (DLA).
Diffusion Limited Aggregation (DLA).
After the last tutorial, here is a 3 dimensional version of a Diffusion Limited Aggregation model, which uses similar code to the example of particles leaving traces on voxels. DLAs have been used as models the growth of coral, sponges or roots and branches, the formation of lightning, or even the growth of cities. There are a number of sophisticated DLA simulations in 3D with quite high resolution, The model here is quite simple, and it also uses the voxel library introduced in the previous tutorial. The principle is basic: a number of particles move around space, and when they bump into a solid voxel, they “stamp” a few voxels around as solid and then are re-spawned somewhere else. For checking the voxels, as in the example before, the 3D positions of the particles are converted into integers corresponding to voxels, like this:
int xPos=round(pos.x); int yPos=round(pos.y); int zPos=round(pos.z);
Observe that we use round() rather than int() to convert the floats of the positions to an integer; this is because int will always convert it to the lowest integer, and this affects the direction of the growth of the DLA. The basic algorithm in draw is as follows:
boolean update=false; //for each particle... for(int i=0;i<particlesPos.length;++i){ calculateNewPosition(i); //now check if the particle has colided with a solid voxel //and if it was, modify the voxels (stamp) and restart the position somwhere //at the bottom of the cube defined by the voxels... if(isOnSolid(particlesPos[i])){ doGaussianStamp(particlesPos[i],gaussianRadius); particlesPos[i].x = random(0.0,DIMX); particlesPos[i].y = random(0.0,DIMY); particlesPos[i].z = 0; //set update to true. The reason of setting a boolean value, instead of generating //the mesh directly, is that if there are more than one particle that colided with //solid voxels, then we only need to generate the mesh once for all of them, instead //of at every collision. update=true; } }
Also, for the particles to have something to bump into in the beginning, a few voxels are seeded as “solid” in the setup(). The results look something like this:
In the example the direction of the particles is downwards (-z) and the seed is placed at the bottom of the volume defined by the voxels; different growing patterns will occur of the direction of the particles and position of the seed are changed. For example, the seed could be placed at the very center, and the particles may move completely randomly; when they encounter a solid (and stamp it), they could re-spawn somewhere on the edge of the boundary. All the 3D meshes can also be exported as .stl files, using the voxel library.