Reputation: 343
I've never understood how something like a mandelbulb can be generated from mathematical data. The only way that makes sense to me is to use voxels, which is obviously not used in the image linked here. So if anyone could explain this to me, please do.
Upvotes: 1
Views: 1393
Reputation: 9
The formula for the Mandelbulb is similar to that of the Mandelbrot set, but with an extra dimension. First, I'll describe how to make the Mandelbrot set using real numbers instead of iterating on complex numbers.
Rather than computing the zero orbit for all the points c inside the r=2 circle z_new = z_old^2 + c
we break the formula up into x and y components using e^(I theta)=cos(theta)+I sin(theta)
Then our formula is
X_new= r^2 cos(2 theta)
Y_new= r^2 sin(2 theta)
where X_old=r cos(theta)
, y_old =r sin(theta)
To take it to three dimensions, we write everything in spherical coordinates
x_old= r sin(phi) cos(theta)
y_old= r sin(phi) sin(theta)
z_old= r cos(phi)
Now we can iterate on
x_new=r^2 sin(phi) cos(2 theta)
y_new=r^2 sin(phi) cos(2 theta)
z_new=r^2 cos(2 phi)
This works because the squaring function in the Mandelbrot equation is replaced by squaring the radius and rotating by twice the angle, and taking it up one dimension is done by adding the same transformation in the z direction. The photo above is the power 8 Mandelbulb, so we replace squaring by the 8th power.
Upvotes: 0
Reputation: 2811
I don't know the exact math but I do know how you can get from 2D fractal to 3D one. But first lets see how you can do a 2D fractal:
When computing a general (2D) fractal you pick some pixel coordinates and transform them with a function, like [x,y] = somefunc(x,y)
and check if the result meets some condition. If it doesn't you reiterate again, and again...
Your numbers may never meet this condition so you add some global counter, let's say 100 iterations per pixel - if it doesn't meet the condition after 100 iterations you assume it never will and stop.
If the condition was never met you assume that current pixel is outside of a fractal, if the condition was met you store the iteration count needed to do so.
Having all of this computed for every pixel you map your iterations number to colors, most often I saw the outside
painted as black and iterations count mapped to some custom color. You may use gradients, bands, grayscale or whatever you want. You may also cycle those colors to fake animation.
One thing to notice here is that when you start computing some pixel then after some iterations you'll end up with a result for that pixel - this will be different in 3D case.
In 3D case most of the computations are the same, just a lot more of them.
You start with some pixel but now you compute the 3D ray from your eyes to that pixel and pick some starting point close to you (like a near clipping plane). You do your iterations for this 3D point, but if you don't meet the condition you advance your point by a small step and recompute everything for this new point. This means it's not enough to compute some iterations to get the result for current pixel - you may need to do this a lot of times, for every tested point along the ray, and this makes your computations a lot slower.
Basically, when you've found the first point that meets your condition and have an iterations count for this point you could color it the same way as in 2D case, but the 3D space gives you more options. You may track the line between this point and a light to check if it's shadowed, or try to compute normal for lighting (there are no typical normals
in fractals but you may try to fake it).
This is a place where you can be most creative - although current computers are too slow to do all this math fast you may find many tricks to help. For example, in the image you've posted I believe they also tracked some proximity of every final point to get ambient occlusion
.
And according to my somefunc
and condition
you can look at the Wiki pages about Mandelbrot and Julia sets. They seem to be very simple but I didn't do it on my own so won't pretend I'm the good person to describe it.
Upvotes: 3