
Coral growth (genetic fractal)
Previous article: Arbitrary branchings
In the previous parts of this series we introduced the idea of genetic fractals, based on a simple formulation, aka the genetic equation. This equation is controlled by driver functions. Initially we started out with a driver function for the progression of the fractals, , and the way in which it bends and swirls,
. We then added accessory functions for color, branch width and even a control for branch points. We could go on and play around graphic attributes and make the branches programmable from an external source. One interesting addition would be to make an accessory function that responds to the environment and use that o influence growth and bending. But all of that is incremental and you can figure this out quite easily.
The last thing we should do is to see how robust the mathematics is and extend the model to 3D. There is a 3D version of the genetic equation. Remember that the two-dimensional exponential form of the Creation Equation is:
Or in trigonometric form:
Using the Spherical Coordinate system, we can write the Genetic Equation in the three dimensional form as shown below. We use a spherical coordinate system with radial distance r, azimuth and inclination
. Refer to Wikipedia for a good description of this good but tricky coordinate system.
, where ,
and
are the driver functions. As before, don’t be too scared of the large number of integrals, they are essentially sums that allow is to “remember” where we are in the tree graph.
To test this, we can simply translate the maths into Ruby code, as shown below. As before, we approximate integration by summation.
def creationEquation3D(dR,dPhi, dTheta, lastPoint, lastPhi, lastTheta) newPhi=lastPhi+dPhi #integrate over phi (it's summation really) newTheta=lastTheta+dTheta #integrate over phi (it's summation really) return [ lastPoint[0]+dR*sin(newPhi)*sin(newTheta), lastPoint[1]+dR*cos(newPhi)*sin(newTheta), lastPoint[2]+dR*cos(newTheta)], newPhi, newTheta end
You might want to compare that with the 2D version of the creation equation in Ruby:
#the Creation Equation is implemented in its trigonemtric form for simplicity def creationEquation(dR,dPhi, lastPoint, lastPhi) newPhi=lastPhi+dPhi #integrate over phi (it's summation really) return [ lastPoint[0]+dR*sin(newPhi), lastPoint[1]+dR*cos(newPhi)], newPhi end
Surprisingly (to me anyway, having been through the wars of 3D CG programming), this 3D version of the creation equation just works, as shown in the image at the top of this post (click to magnify). No tweaks needed. That, is the power of maths, and that is also the perfect message to end this series with. Hope you liked it 🙂
Previous article: Arbitrary branchings
Pingback: 2D genetic fractals makers guide (part 4): Arbitrary branchings | Genetic Fractals Laboratory