Sierpinski cube

To construct a Sierpinski cube, like the Sierpinski carpet but one dimension higher, we start with a cube at level 0. To obtain the set at level 1, partition the cube into 3^3 = 27 subcubes and then retain those subcubes that share a corner or an edge with the original cube (there are 20 such subcubes). To see what I mean, select Sierpinski cube from the dropdown menu and nbrLevels 1 from the following program.

Sierpinski cube and other fractals

Generally, level n+1 sets are obtained by applying the same rule to the level n set. The resulting Sierpinski cube is a higher-dimensional analogue of the Sierpinski carpet and the Cantor set. Since magnification by a factor of 3 increases the size by 20, its fractal dimension is d = \log_3 20 \approx 2.73.

To construct a Sierpinski cube, call makeCantor3 and pass function retainSierpinskiCube as the first argument.

function makeCantor3(retainF, level, mat, len=1) {
    if (level == 0) {
        let geom = new THREE.BoxGeometry(len, len, len);
        return new THREE.Mesh(geom, mat);
    } else {
        let cantor = makeCantor3(retainF, level-1, mat, len);
        let root = new THREE.Object3D();
        root.scale.set(1/3, 1/3, 1/3);
        for (x of [-len, 0, len]) {
            for (y of [-len, 0, len]) {
                for (z of [-len, 0, len]) {
                    if (retainF(x, y, z, len)) {
                        let clone = cantor.clone();
                        clone.position.set(x, y, z);
                        root.add(clone);
                    }
                }
            }
        }
        return root;
    }
}

function retainSierpinskiCube(x, y, z, len) {
    return (Math.abs(x) + Math.abs(y) + Math.abs(z)) > len;
}

The Mosely snowflake is constructed like the Sierpinski cube but using a different rule: At each iteration, the 8 corner subcubes are deleted and the remaining 19 subcubes are retained. Select Mosely snowflake from the dropdown menu and choose level 1 for a picture of this. Because size increases by a factor of 19 under three-fold magnification, its fractal dimension is d = \log_3 19 \approx 2.68. The ‘light’ Mosely snowflake follows the same rule but also deletes the center subcube, leaving 18 subcubes. (You need to build the level 2 set to see the difference.) Its fractal dimension is d = \log_3 18 \approx 2.63. To construct these two fractal variants, call makeCantor3 with one of the following functions:

function retainMoselySnowflake(x, y, z, len) {
    return (Math.abs(x) + Math.abs(y) + Math.abs(z)) < 3 * len;
}

function retainMoselySnowflakeLight(x, y, z, len) {
    let val = Math.abs(x) + Math.abs(y) + Math.abs(z);
    return (val < 3 * len) && (val > 0);
}

An SM (Sierpinski-Mosely) snowflake is the intersection of the Sierpinski cube and Mosely snowflake. The rule is to retain those subcubes which are retained by both the Sierpinski cube and the Mosely snowflake rules. Select SM snowflake from the dropdown menu and nbrLevels 1 for a picture of this rule. Since size increases by a factor of 12 under three-fold magnification, its fractal dimension is d = \log_3 12 \approx 2.26. You can see that it appears less substantial than the previous two fractals.

function retainSMSnowflake(x, y, z, len) {
    return retainSierpinskiCube(x, y, z, len) && retainMoselySnowflake(x, y, z, len);
}