Getting older, not necessarily wiser!
It is time to discuss the math behind Sierpinski’s Pyramid. In the previous post we discussed some aspects of writing POV Ray scene scripting.language. This is a slight departure into the theory and math of the object we are modeling
As previously alluded too, the pyramid is an extrusion of Sierpinski’s Triangle or Gasket. We have not really discussed what it is or how it is derived.
Fractal: Sierpinski’s Triangle is a type of fractal. A fractal is a mathematical structure that contains detailed structures at an arbitrary magnification. This fractal has similar expanding symmetry at different magnifications.
Creating Sierpinski’s Triangle: The most common rendering is based on an equilateral triangle where all sides are equal and all angles are 60 degrees. However, almost any triangle will work. Its just a matter of figuring out the math.
Starting with a triangle of arbitrary size, it is replaced with three triangles that are one half the size. One going at the top of the original triangle, and the other two going at the corners of the original triangle. This leaves a half size upside down triangular hole in the center.
Now we take one of the new triangles and replace it with three half size triangles (¼ size of the original triangle) in a similar manner. We do this to each of the half size triangles. Then we divide our new quarter size triangles in half, and repeat the same procedure. This can go on forever with smaller and smaller triangles.
The above three pictures show the triangle with three down scales, or a recursion depth of three. The first image has one triangle, the second image has three triangles, and the third image has nine triangles. If we went to a recursion depth of four, there would be twenty seven triangles. Obviously this can quickly become problematic to draw manually.
In the pyramid, we extend into a third dimension, giving the triangle depth. This means five pyramids (one top and four corners), then twenty five pyramids, and at the next level there would be one hundred and twenty five pyramids.
This is where loops and recursion come into play. We just need to identify how the smaller pyramid moves in relation to its larger parent. Then we can loop through adjusting the math as we go. Lucky for us the math will remain the same, just at a smaller and smaller scale with each additional depth of recursion.
The base pyramid I will be using has base lengths of two units in the X and Z directions (-1 to 1), and one unit in the Y direction (0 to 1).
A child of our main pyramid will have a 1 x 1 base and a height of 0.5. There will be a total of five child pyramids, and each will require one of the five movements below. Note theses are in referenced to the parent triangle size (not units, so the math should apply at all levels of recursion).
This tells us we will need five equations that can call themselves to calculate smaller and smaller pyramids.
This also brings up a point. We need to to set a recursive value, to test against. Otherwise our recursions would continue forever (or until you ran out of RAM and the program crashed).
In this post we put together a level one recursion of Sierpinski’s Pyramid. We pretty much did it by hand. In the next post we will work out how to use recursion with the math we set up here to render to any recursion depth.
Sierpinski Pyramid POVRay Part 3