# 3D Fractals

## Intro

A fractal is a “curve or geometric figure, each part of which has the same statistical character as the whole”  that is represented by a complex equation. Because these equations are infinite and so complex, it would be impossible to represent them at a set of vertices. One technique that is used to circumvent this problem is ray marching using distance estimator formulas. Put simply, this technique works by calculating the distance from the current pixel to the boundary of the fractal set. 

## Ray Marching

"Classic raytracing shoots one (or more) rays per pixel and calculate where the rays intersect the geometry in the scene.”  Ray marching uses a similar technique, but because the geometry in the scene is not defined by a set of vertices, we must use a different technique to find intersections. We march along the ray, each time using a distance estimator function to see how far we are from the fractal set. Once we are within a specified distance of the set, we stop.

## Distance Estimators

The distance estimator will be different for each fractal. Although it is important to understand these functions, we did not write these ourselves. To understand the concept of these distance estimators, it is important to understand that the fractals (or at least two of them) we used are what is called “escape-time” fractals. This means, “we iterate a function for each point in space, and follow the orbit to see whether the sequence of points diverge for a maximum number of iterations, or whether the sequence stays inside a fixed escape radius.” 

One fractal we chose to represent is not an escape-time fractal, but rather an iterated function system (IFS) . This complicated term basically means that “the fractal is made up of the union of several copies of itself, each copy being transformed by a function” 

## Mandelbulb, Mandelbox, and Menger Sponge

The fractals we chose to represent are the Mandelbulb, Mandelbox, and Menger Sponge.

The Mandelbulb is “a three-dimensional analogue of the Mandelbrot set”.  In order to understand this complex object, we must first understand the Mandelbrot set. The Mandelbrot set is a 2D fractal represented by the points that do not diverge for the equation zn+1=zn2+c and is pictured below. To arrive at the 3D version of this fractal, the equation is simply changed to zn+1=zn8+c. The Mandelbox is similar to the Mandelbulb, but instead of an equation of the format zn+1=zn8+c, it is represented using complex operations called folds. Put simply, the algorithm works by using a shape, such as a sphere or cube, and some planes of symmetry. If a point is inside of this sphere or cube, we reflect it across the planes.

As mentioned before, the Menger Sponge is an iterated function system (IFS). In the case of the Menger Sponge, we can construct the IFS using the following steps:

1. Begin with a cube (first image).
2. Divide every face of the cube into 9 squares, like a Rubik's Cube. This will sub-divide the cube into 27 smaller cubes.
3. Remove the smaller cube in the middle of each face, and remove the smaller cube in the very center of the larger cube, leaving 20 smaller cubes (second image). This is a level-1 Menger sponge (resembling a Void Cube).
4. Repeat steps 2 and 3 for each of the remaining smaller cubes, and continue to iterate ad infinitum. ## Our Process

We began our process by using the distance estimator to create a grayscale picture. We used the amount of steps taken in the ray marching to represent a grayscale value. The result: The next step was to do lighting and shading. The results: The biggest and most important step was implementing looking and walking around. The results: After getting everything else finished, the last step was coloring. For coloring we used a technique called orbit traps, a technique which "keeps track of how close the orbit comes to a chosen geometric object."  The results: Final product for Mandelbox  Final product for Menger Sponge: ## References:

1. Marks-Tarlow, Terry. "Terms & Definitions." Complexity Space Consulting RSS. Complexity Space Consulting, n.d. Web. 11 June 2013.
2. Quilez, Iñigo. "Iñigo Quilez - Fractals, Computer Graphics, Mathematics, Demoscene and More." Iñigo Quilez - Fractals, Computer Graphics, Mathematics, Demoscene and More. N.p., n.d. Web. 11 June 2013.
3. Christensen, Mikael H. "Syntopia." Syntopia. N.p., 3 June 2011. Web. 11 June 2013.
4. "Iterated Function Systems." Wikipedia. Wikimedia Foundation, 06 Oct. 2013. Web. 11 June 2013.
5. "Menger Sponge." Wikipedia. Wikimedia Foundation, 15 May 2013. Web. 11 June 2013.
6. "Mandelbulb." Wikipedia. Wikimedia Foundation, 22 May 2013. Web. 11 June 2013.