Fun with Mandelbulbs and 3d printers


2d mandelbrot sets have been around for a while, and there have been various tricks to turn those into 3d views (typically by turning the iteration count into a height). However at the end of 2009 a number of articles appeared about true 3d fractals similar to the Mandelbrot set called 'mandelbulbs'.

While I don't pretend to understand the original maths of the Mandelbrot and the Mandelbulb actually writing programs to render a Mandelbrot is pretty simple; for every point you just repeatedly apply the same equation over again to a value and count the number of iterations until it exceeds an escape value. At some point you give up and determine that the point won't ever hit the escape value. For a 2d mandelbrot you then just draw a picture with a different colour at each point using the iteration count to determine the colour.

Fortunately a nice website on the mandelbulb has an explanation and the equation to use. I put together a *really* simple program to use that equation and produced a 512x512x512 voxel array that looked something like the examples shown on the page that explained the Mandelbulb.

Viewing the mandelbulb

Viewing a rendering of the mandelbrot is easy - it's just an image; things just aren't as simple in 3d. One approach is to build the iteration algorithm into a ray-tracer and directly produce a 3d image. I opted to work with the voxel array I'd produced. Voxels are the 3d equivalent of pixels - think of an NxNxN stack of sugar cubes. You can view a 2d slice easily enough by just extracting it as an image, but to view the whole 3d model something a bit smarter is needed.

I used the free Amide software (originally designed for medical imaging) to view my voxel file and it has a rendering feature that produced the following image:

Rendering of power 8 mandelbulb by Amide

Fun with 3d printers

With the buzz of 3d printers that had been around for the last couple of years I'd hoped to produce a physical copy of the mandelbulb, and in April 2010 Fab lab manchester opened just outside the centre of Manchester.

Fablab have a Dimension 1200es 3d printer. There are a few different 3d printers out there that use various different technologies; the Dimension appears to extrude one of two different plastics along a path on each layer, then moving along to the next layer. One of the plastics is a hard ABS plastic, the other is a soluble support material. The software that drives the printer takes as input an STL file which is a collection of triangles. It then automatically drives the printer, inserting the support material where needed to keep the model up while it is printed.

Using the description of the STL file from Wikipedia I wrote a Simple voxel to STL converter. This is pretty simple and just inserts a cube everywhere the voxel is set, removing faces of the cube that are also included in another cube. These files are not small! The simple STL file for a 512x512x512 mandelbulb came out as 1.4G, while the 256x256x256 that I eventually used was 220MB. I used the free meshlab software to make sure I'd produced a valid STL file and view the result:

Rendering of power 8 mandelbulb by Meshlab

The Dimension printer has a resolution of about 0.25mm, and I opted to produce a small model about 4cm across, given that's only about 160 times the resolution I used the smaller 256x256x256 STL file. I'd been rather worried that the printer might object to the rather complex STL file, but it took it without any problem. The only complication was that the STL file is dimensionless, and thus the file I produced represented something either 1mm or 1inch across depending on how I asked Dimension's software to interepret it; the software lets you scale it up to whatever size you want.

After a while of plotting and then dissolving of the support we have the following:

Photo of the printed mandelbulb with shadow

I do like the fractal shadow on that image. Some other thoughts:

  1. Different 3d printers have different input formats, limitations and preferences.
  2. Given the finite resolution there are a handful of points that pass the iteration limit that are not connected to the main object. This might upset some 3d printers; the dimension was OK with this (and probably got washed away as the support disolved). Meshlab has some tools for filtering out unconnected blocks.
  3. It's not clear if a better STL file would improve the result - I've produced output using a marching cube algorithm but haven't tried printing it.
  4. There are lots of ways to improve the simple programs included here including parallelising them, and using smarter algorithms to improve the speed of the fractal rendering.

Many thanks to all at Fab lab Manchester, Daniel White for his Mandelbulb page, and the authors of Amide and Meshlab. All my rendering was produced on a system running Ubuntu Linux.

(c)Dave Gilbert 2010 - feel free to use the code examples and quote this page as long as you acknowledge me.

My home page