What Math to learn for Fractal Design?
October 14, 2011 9:56 AM   Subscribe

Knowing basic algebra, what math would I need to learn so that I could eventually program fractal movies?

I have a huge interest in Fractals and want to understand the math behind them so I can explore in more depth. I excelled at math, but only took classes through Trig. That was about 20 years ago...

I work as a programmer, so still use a lot of algebra and loved geometry, but haven't had a need for it in adult life. Expecting that I'd have to brush up on what I learned, what areas of math would I have to cover to get to a full understanding of the math and concepts behind complex fractal generation?

What web resources could I use to learn in more depth specifically about fractals after understanding the underlying math?

I want to be able to code fractal movies as the culmination of my study. I know there are some great visual tools to do things like this, but I want to know the math behind it so I can get closer to exactly what I want.

Thank you.
posted by davathar to Education (10 answers total) 6 users marked this as a favorite
 
The math isn't very complicated, actually. A mandlebrot set is a simple iterated function.

Basically, you map out the complex number plane (the y axis is the imagination numbers, and the x axis is the real numbers.

Then for each point c in the plane, you start with z=0 and just do a loop like this:

z = z^2 + c

and repeat for some arbitrary number of steps.

After a certain number of steps, it's in the set if it goes to 0 or stays below a certain value, and it's out of the set if it runs off to infinity. You can also do coloring based on how many steps it takes to reach some arbitrary value.

An animation of a mandlebrot set is just a set of successive renderings of different parts of the complex plane with different resolutions.

There's actually code on the wikipedia page itself.

Fractal math can get very complicated, but just making animations isn't particularly.

There are other types of fractals, of course, but none of them are very hard to generate. That's part of the beauty of fractals and why they're so fascinating -- endless complexity out of very simple formulae.
posted by empath at 10:23 AM on October 14, 2011


James Gleick wrote a book about fractals called "Chaos: the making of a new science" which is a very good overview, but I haven't read it in a while, so I don't know how out of date it is.
posted by empath at 10:25 AM on October 14, 2011


I asked a similar question a while back and got some amazing answers.
posted by bondcliff at 10:25 AM on October 14, 2011 [1 favorite]


Response by poster: As an example of what I'm hoping to accomplish, I want to be able to make things like this. http://ericbigas.com/fractals/index.html

@bondcliff I saw your post when looking for an already answered question, but for some reason based on the title thought it was something else. Turns out there are indeed some good answers and references. Thank you for that.

I know that the basic formula for many fractals is quite simple. But to get to the level of being able to really manipulate everything from the coloration, to zooming and tracking along the plane, I think it's going to take a bit more complex math.

Even in the Eric Bigas animations there are sharp turns where the animation stops tracking one direction and starts in another. When I do it, I want the turns to be smoothed out as if the viewer was flying and had to consider the physics of acceleration.

His videos are a lot more than just pan and zoom too. The visual nature of the fractal seems to change dramatically at some points like from boxes to tree branches. And it's not just the effect of zooming into distant self similarity. It happens while looking at the same set of coordinates. So there has to be some changing of the formula or parameters other than zooming.
posted by davathar at 10:44 AM on October 14, 2011


I know that the basic formula for many fractals is quite simple. But to get to the level of being able to really manipulate everything from the coloration, to zooming and tracking along the plane, I think it's going to take a bit more complex math.

Even in the Eric Bigas animations there are sharp turns where the animation stops tracking one direction and starts in another. When I do it, I want the turns to be smoothed out as if the viewer was flying and had to consider the physics of acceleration.


It really isn't. Every frame is just a rendering of part of the complex plane at a certain resolution. A 2x zoom is simply a series of renders between rendering, say from -1 to +1 to -.5 to +.5

The only choice you make for the animation is what range you're rendering.

You can set the coloring as a set of parameters which also smoothly change during the animation -- you can set what your escape value is, which colors you use to represent them, etc...

It really is as simple as just changing the parameters. Load up fractint and play around with it, and you'll see what I mean.

Although some of the 3d fractals (and 4d fractals, which are made by mixing the mandlebrot set with the related julia sets) can get pretty complex, animations of 2d fractals are generally pretty simple.
posted by empath at 11:20 AM on October 14, 2011


Best answer: This is going to be a learning experience for you. You can do a heck of a lot of computer graphics with little more than what, back in my day, was high school sophomore level algebra and trig. It's a little easier with matrix math, but luckily nowadays high school algebra includes dealing with matrices.

First: Write a mandelbrot set viewer. As empath said, z=z2+c on the complex plane. Use "double" math types, don't try to zoom in too far (if you're seeing large square pixels, you're zooming in to far, my first pass circa 25 years ago used floats...). Understand what's happening with that. Color it with a palette based on the number of iterations you have to do to get it to diverge. I could swear I'd tossed code on the web somewhere to do this, but I don't find it. However, many other people have, and it's really simple.

Second: Now that you're able to evaluate the Mandelbrot set at a series of points, implement rotation. The way I'd do this: Rather than a position and a width and a height to render, take a position and two vectors to render along. If you have a renderMandelbrot(double x, double y, double width, double height), change that to renderMandelbrot(double x, double y, double wx, double wy, double hx, double hy) and call it with renderMandlebrot(x,y, sin(angle) * width, cos(angle) * width, sin(angle+90°) * height, cos(angle+90°) * height) (note that your trig library likely uses radians, not degrees, so you'll have to get that right). Figure out why your picture is probably now mirrored vertically, and how to make it shear and so forth.

Third: Make an animation that moves linearly along a path. Since you already know how to step along a vector, you figured that out in the second step, you do the same thing for your origin. Do something similar for rotation.

Fourth: Make an animation that moves along a Bezier curve. You can find code out there to evaluate a Bezier curve as a function of t where t is between 0 and 1 inclusive.... Replace your vector step with this. The cool bit? You can manipulate the control points on that vector to do ease-in and ease-out along a line.

Fifth: Play with other ways to do ease-in and ease-out. Now that you've gotten this far, you'll have all sorts of ideas for how to do that. If nothing else, think about how you can pervert Bezier curves feeding into Bezier curves, but you're probably smarter than just that.

Sixth: Replace the Mandelbrot set with something else. This is where that last part, where the "visual nature of the fractal seems to change dramatically at some points" starts to happen. Although there's a heck of a lot of fun to be had flying around the Mandelbrot set.

There's nothing in those six steps that's beyond a smart high school student, especially with web the way it is now. Back in the day there used to be some tools to do a good portion of this, but if you want to do things that are better than what other people are already doing, you're going to have to learn enough to build on that.

And have fun. After you do a bit of this, you can start playing with ray tracers and build a simple 3d renderer. Maybe implement your code in a parallel language like Cg or something and run it on your graphics hardware. There's a lot to learn, and it's all super fun!
posted by straw at 11:22 AM on October 14, 2011 [5 favorites]


Ugh. Need to look at my "preview" more closely: Apparently the MeFi escaper won't let me do this symbolically, so "...evaluate a Bezier curve as a function of t where t is between 0 and 1 inclusive..."
posted by straw at 11:25 AM on October 14, 2011


Response by poster: Yes, there is a lot to learn...

I barely remember trig, and have a hard enough time working with Bezier curves in Photoshop!

But this is totally for fun, so I'm looking forward to taking some time to get deeper into it.

I've played around with Fractint probably since about 95. I remember it as a DOS program. It was amazing back then. But over the years when I've tried it again, I get lost in the complexities of the parameters. I simply don't understand the math they are talking about. So I end up just changing things arbitrarily and seeing what happens. I want to know why to change something to get specific effects.

I use linux primarily now and would love to know of the best native linux programs.

Thank you for all the great input so far!
posted by davathar at 11:39 AM on October 14, 2011


Ages ago, like the BBS era of the late '80s, I started collecting a series on doing computer graphics with high school math. I didn't get terribly far, somewhere in there I learned how to use matrices effectively and (I've linked to one of my personal sites, so I guess my anonymity is blown) I ended up at Pixar for a few years and the whole landscape changed dramatically for me, but somewhere in the dingy recesses of Dr. Dobb's Journal there was an article on doing ray tracing in C using high school algebra. Way back in the day.

Anyway, this is the long way of saying that I went to that page, clicked on my Mandelbrot generator link, and it was broken. So I took 10 minutes and did step 1 of my suggestions above, in C. It's very "command line" oriented, as simple as I could make it, and requires that you have the ImageMagick tools installed in order to convert the raw file to something you can read.

It's amazingly stupid and obtuse and the sort of thing I would have written when I was a teenager, and took me about 10 minutes, but here's a super simple Mandelbrot generator written in C, including a Makefile. Install ImageMagick, copy and paste the C into "mandel.c", copy and paste the Makefile into a file called "Makefile", go to the directory you saved those files into and type "make", hit enter, get an ugly picture.

Understanding that code and making that picture prettier is your first step.

Go nuts.
posted by straw at 1:07 PM on October 14, 2011


Get a copy of Fractint and play around with it. I found it in my teens when the whole fractal thing got really big and basically taught me the power of iterative functions in many applications. It's got a TON of built in formulas, but you can also plug in your own and it will dutifully render them. It's got a slew of coloring options and rendering options(tessalation is pretty neat).

You may also want to look in to L-Systems. If you want to play around with L-Systems RIGHT NOW, have a look at this L-Systems HTML5/Canvas demo.
posted by mnology at 9:26 AM on October 21, 2011


« Older Is There a Job Application Web App?   |   Have I been given the wong (tracking) number here... Newer »
This thread is closed to new comments.