Maths Town (title)
Maths Town (title)
Home News After Effects Plugins Code Blog Complex Functions Fractal Articles Fractal Videos

The Mandelbulb Fractal

Many people have dreamed of extending the Mandelbrot Set into three dimensions, but a problem arises because the complex numbers don’t naturally extend into 3D. The Mandelbulb fractal is an attempt to solve this dilemma. It is a 3D fractal created by extending some of the Mandelbrot’s geometric properties into the third dimension. The Mandelbulb isn't considered the true 3D Mandelbrot, but it is still a fascinating fractal.

While the Mandelbulb has some features in common with the Mandelbrot Set, there is one important feature is missing. The Mandelbulb formula is not conformal; it contains stretching and distortion. Despite such technicalities, the result is a beautiful fractal we can explore. I’ve rendered high-resolution images of each power for you to explore below.

The Formula.

So where does the formula come from? Remember that the Mandelbrot formula is z = z^2 + c. The squaring operation has an interesting geometric interpretation on the complex plane. In polar coordinates, a radius and an angle can represent any point. When we square z, the radius is squared, and the angle is doubled. The Mandelbulb simply extends this idea to spherical coordinates. We square the radius and double both of the angles.

This idea also extends to the higher powers. We can raise the radius to required power and multiply the angles accordingly. It is traditional to render the Mandelbulb using the 8th power. However, there is a unique fractal for each power.

I won’t bother with tricky mathematical notation. Let’s just look at the code.

//Convert to spherical coordinates
float r = sqrt(x*x + y*y + z*z);
float theta = acos(z / r);
float phi = atan2(y, x);

//Scale and rotate
r = pow(r, power);
theta *= power;
phi *= power;

//Convert back to cartesian coordinates
x = r * sin(theta) * cos(phi);
y = r * sin(theta) * sin(phi); 
z = r * cos(theta);

//Add c
x += c_x;
y += c_y;
z += c_z;

To check if a point is within the Mandelbulb, we simply iterate over this formula. If the radius becomes large and escapes, the point is not in the Mandelbulb. If it remains contained, then it is part of the fractal.

Below is a simple function to check if a point is within the Mandelbulb.  Of course, you could optimise away a few calculations, but I’ve tried to keep it simple for clarity.  In fact, sometimes you can optimise away all the trigonometric expressions, but more on that in another article. I’ve rendered high-resolution images of each power for you to explore below.

//Inputs:
//  (c_x, c_y, c_z) = Location of point.
//  power = The power of Mandelbulb to render (tradionally 8)
//Returns:
//  true if the point is in the set, false otherwise.

bool mandelbulb(float c_x, float c_y, float c_z, int power){{
    float x = 0.0;
    float y = 0.0;
    float z = 0.0;

    for (int i=0; i < MAX_ITERATIONS; i++){
        //Convert to spherical coordinates
        float r = sqrt(x*x + y*y + z*z);
        float theta = acos(z / r);
        float phi = atan2(y, x);

        //Scale and rotate
        r = pow(r, power);
        theta *= power;
        phi *= power;

        //Convert back to cartesian coordinates
        x = r * sin(theta) * cos(phi);
        y = r * sin(theta) * sin(phi); 
        z = r * cos(theta);

        //Add c
        x += c_x;
        y += c_y;
        z += c_z;

        //Check if the radius is not beyond the bailout.
        if (sqrt(x*x + y*y + z*z) > BAILOUT) return false;
    }
    return true;
}

Unlike Mandelbrot images, we rarely colour the outside of the fractal. The outside is transparent. To add colour to the images on this page, I have used the orbit trap colouring method.

Despite the simplicity of the formula, rendering of the Mandelbulb fractal can be a complex task. There are two main approaches. The voxel method creates an array of spheres or squares, then checks whether each is contained within the set. The second approach is to use ray-marching, a form of ray-tracing. Ray-marching is more complex because it involves calculating distance approximations, but the results can be worth the trouble. I rendered all the images in this article using the ray-marching method.

Mandelbulb Fractal Images by Power

Click on an image to view it in high resolution 8k. I rendered each image using 1000 iterations at 32 bit precision, using the trigonometric method. You may reuse all the images on this page under the terms of the Creative Commons Attribution License.

Mandelbulb Power 2

When it was first discovered, the Mandelbulb was considered uninteresting. However, now that we have the computer power to render it in high resolution, we can see that parts of it are quite interesting. Like the Mandelbulb, it has a spike, which contains mini objects.

The Mandelbulb Power 2 viewed from each side of the three axis.

Mandelbulb Power 3

Notice that the power 3 does not have a spike. In fact, all the odd powers have no spike.

Mandelbulb Power 4

The power 4 has a spike, but it is much smaller than the power 2.

Mandelbulb Power 5

Mandelbulb Power 6

Mandelbulb Power 7

Mandelbulb Power 8

The 8th power is traditionally considered the standard Mandelbulb.

Mandelbulb Power 9

Mandelbulb Power 10

Mandelbulb Power 11

Mandelbulb Power 12

Mandelbulb Power 13

Mandelbulb Power 14

Mandelbulb Power 15

Mandelbulb Power 16

Mandelbulb Power 17

Mandelbulb Power 18

Mandelbulb Power 19

Mandelbulb Power 20

Mandelbulb Power 30

Mandelbulb Power 40

Mandelbulb Power 50

Mandelbulb Power 60