Wednesday, February 08, 2006

Fractals

Fractals are images that have repeating elements at any scale -- their resolution is infinite. I had an assignment in CS class to make a computer program to generate a fractal by looping through each pixel and determining the color. Here is one of the fractals my program created:


The program renders grayscale pixels whose brightness is determined by a series of mathematical operations. It works like this:

  1. Each pixel represents a number in the complex plane. The real component ranges from -1 to 1, and the imaginary component ranges from -i to i. The center of the image is the origin, which represents 0 + 0i, or just 0.

  2. The program is given the function F(z) = z^4 - 1. The roots of this function are 1, -1, i, and -i, but the program doesn't know this. For each pixel, the program uses Newton's method to calculate one of the roots of the function given an initial guess z0 that corresponds to the pixel's location in the complex plane.

  3. Newton's method figures out roots of a function by generating a series of guesses, each one dependent on the last, and usually the guesses tend toward one of the function's roots. The program is satisfied that Newton's method has found a root of F(z) when the function of the k'th guess, F(zk), is between -0.00001 and 0.00001.

  4. The program then looks at the value of k -- the amount of successive guesses it took Newton's method to arrive at one of the function's four roots. The fewer guesses it took, the brighter it renders the current pixel. Thus, a pixel's brightness measures efficiency with which Newton's method finds a root of F with the starting guess being at that pixel's location.

  5. But if a pixel is located near to one of the four roots, it should be easier for Newton's method to refine a guess starting from that pixel's location. So each pixel is multiplied by a constant that darkens it in proportion to how close it is to any one of the four corners. Notice the dark spots in each of the four compass directions -- those are the locations of the roots.

Now assuming you roughly understand the process by which this fractal was generated, imagine trying to visualize the image in your head without having seen the computer generated image. You couldn't. So as a result, you wouldn't be able to get some insights about, for example, the efficiency of Newton's method at various locations.

Aren't fractals and computers great?

1 comment:

Anonymous said...

That's actually really cool.

-Boaz