The Mandelbulb

Fractals can exist in any number of dimensions. The classic Mandelbrot set can be generalized to 3D and beyond. In its original 2D form, the Mandelbrot set is defined as the set of all complex numbers, C, where if you repeat the following formula forever, Z does not grow infinitely large:
Z = Z2 + C
But what makes this special? Geometrically, it is a rotation. A complex number is just a point in two dimensions. It can be expressed as a direction, θ, and distance, r, outward from the origin.
Using Euler's Formula, the distance and direction can be written directly as a complex number in exponential notation:
z = reiθ = r(cos(θ) + isin(θ))
Therefore, using elementary algebra:
z2 = (reiθ)(reiθ) = r2eiθ + iθ = r2e2iθ
In other words, squaring a complex number squares the distance and rotates the point by its own angle.
These rotations are what create the infinite swirly patterns in the Mandelbrot set. For each sample point, it rotates around and around by repeatedly adding the point, C, and squaring the cumulative value, Z, until it either diverges to infinity or stays finite. However, the exact angle of rotation depends on the point itself, which creates different harmonics for even the most subtle changes, that add up over many iterations to produce wildly different patterns!
↗ Click to open in the Mandelbrot viewer.
But how do we extend this to three dimensions? Complex numbers have no equivalent in three dimensions. (The "next" set of numbers is quaternions, which exist in 4D. The Mandelbrot formula can be calculated and projected into 3D. Unfortunately, the fractal is mostly a blob of whipped cream, and not the majestic maze of swirls and curls it is in 2D.)
Instead, we use polar coordinates. A point in 3D can be represented as a latitude and longitude on a sphere (like the Earth), where the radius of the sphere is the distance from the origin. Instead of (x,y,z), the three components are (ρ, φ, θ), representing (radius, latitude, longitude).
To extend the Mandelbrot formula to 3D, the cumulative value, Z, is converted to polar coordinates in each iteration, the radius is squared, and both angles are doubled. Then it is converted back to rectangular coordinates and the test point, C, is added. This rotation is the key part of the generalized formula that produces Mandelbrot-like swirls. The power is actually an arbitrary choice:
Z = Zk + C = rkeikθ
In the formula for 3D, there is a radius and two angle components, but the same procedure applies. We exponentiate the radius by k and multiply the angles by k: (ρk, kφ, kθ)

↗ Click to open in the Mandelbulb viewer.
As you can see, the outline is the familiar Mandelbrot shape, since when the latitude is zero, the 3D formula is identical to the 2D formula. (The extra spikes are actually above or below the plane, which you can see if you rotate the shape in the 3D viewer.)
Although it successfully preserves the beauty of the Mandelbrot set, the extra dimension introduces a lot of wasted space between the swirls. This is where the arbitrary power k comes in. When you raise Z to a higher power, it creates more bulb-like features in the fractal, hence the name "Mandelbulb". Here is an image where k = 8, which is the most popular power.

↗ Click to open in the Mandelbulb viewer.
As with all fractals, the details truly shine when you zoom in!


↗ Click to open in the Mandelbulb viewer.
Other powers are interesting too, and you can experiment with them in the viewer. You can also add a constant offset to the latitude angle, which changes the wrinkles at the poles. If you animate it (drag the slider slowly), it creates a neat unfolding effect!