Box Counting 4D fractals

Written by Paul Bourke
October 2026


The following discusses box counting of 4D objects, specifically aimed at quaternion (4D) fractals. It follows a series of box counting implementations by the author starting with a fractal dimension calculator written in the early 1990s. One variant of this was based upon an image, the black parts were deemed to be the object, another variant used the compass dimension and was based upon a collection of line segments. This was extended to estimates for 3D point sets and volumetric data. All these implementations were based upon data, for example, images and vertices. The following is intended to compute the box counting dimension estimate in 4 dimensions and it is based upon an analytic expression for the quaternion fractal. In practice this means that determining whether a position is on the interior or exterior of the set involves computing the quaternion series. While this is less efficient compared to pre-computing the set first, that wasn't possible due to the data involved in storing a 4D volume at reasonable resolution. Of course, extending this to non-quaternion 4D geometry would be straightforward.

The theory for the box counting can be found elsewhere and it won't be repeated here. The verbal description is that for a range of box sizes one calculates the (minimum) number of boxes required to cover the object. The box counting dimension is then the slope of the graph of the logarithm of the box count vs the negative of the logarithm of the box size. This follows the intuitive sense of dimension for integer dimensions. For example, if one counted the number of squares of side length "s" that were required to cover a 2D shape, that number would increase fourfold (22) if the side length were halved. Similarly, if one used rulers of length "s" to measure a 1D line then that estimated length of the line would increase linearly with "s". And if one used cubes of side length "s" to measure the volume of a 3D shape, the number of cubes would increase by a factor of 8 (23) if the side length was halved.

A bit more formally, if N(s) is the number of boxes required to cover the object then N(s) will be proportional to 1/sD where "D" is the dimension.

So, if one plots log(N(s)) against log(1/s) the slope will be the estimate of the dimension, which may not be integer for fractal objects.

The algorithm readily extends to higher dimensions. In 4 dimensions one uses a hypercube of side length "s" and the (minimum) number of hypercubes required for coverage are computed for a number of hypercube sizes.

One can test the algorithm by applying it to objects of known dimensionality, specifically a line, plane, cube and hypercube, all embedded in 4D space. The results for these 4 objects are illustrated below along with their estimated dimension. It can be noted that in general, box counting dimension is a lower estimate of the dimension. This arises due to a bias in the coverage for small and large boxes with respect to the resolution at which the object is being sampled. For example, for large boxes the box count is eventually 1 for all box sizes.

The strict definition for the box counting dimension requires that one finds the minimum covering at each box size. This is achieved by offsetting the origin of the box placement. An exhaustive search through all possible origins would be computationally prohibitive (actually infinite) so instead a number of random displacements are made. The number of random displacements can be chosen in order to balance estimate reliability vs computation time. To further find the minimum coverage the grid could also be rotated at different angles, this was deemed to be prohibitively expensive computationally. The implementation here allows one to specify the number of random offsets for the smallest box size, this is proportionately increased for the larger box sizes. The results illustrate the reduced spread of 5 fractal dimension estimates at each random offset for the quaternion Mandelbrot, defined in quaternion space as the behaviour of the series below.

Clearly, finding the minimum coverage is key to obtaining a reliable estimate of the fractal dimension. Please note that the estimates for the test objects above, a reasonably large number of random offsets was used. Note also that the number of offsets quoted refers to the smallest box size used, the number is increased proportionately for larger box sizes.

The command line for this 4D box counting estimator is shown below.

Usage: 4dfdc [options] identifiername
Options
   -t n         Test cases, n=0 for quaternion
   -r n         Number of random offsets at the smallest box size, default: 1
   -b1 r a b c  The minimum bounding box value
   -b2 r a b c  The maximum bounding box value
   -s1 n        The minimum box size, default: 0.05
   -s2 n        The maximum box size, default: 0.5
   -d n         The resolution the fractal is sampled at, default: 0.05
   -p n         Power of the tricorn, default: 2
   -v           Enable verbose mode

The initial motivation for this box counting dimension calculation was to determine/compare the dimension on multicorn fractals in quaternion space, that is, fractals of the form shown below for some integer power "p".

The results as a function of power "p" shown below.