Assignment 1 Generating and viewing the Menger sponge Solution

$30.00 $26.40


The Menger sponge is an important object in mathematics and the theory of fractals. The figures below show how it can be constructed.

1) Start with a layer of 9 cubes.

2) Remove the cube in the middle.


lu1871jkte47 tmp 22e48836c8c042e8

3) Create next layer of the sponge by adding 4 cubes in the corners, as shown.

lu1871jkte47 tmp 2591fbbce5cfebc0

  1. Add the third layer, which has the same structure as the first layer shown in Step 2. If you wish, you may think if this object as a cube subdivided into 17 sub-cubes, 7 of which have been removed (one in the bottom layer, 5 in the middle, and 1 in the top layer.)


lu1871jkte47 tmp 980312caaeff6a6

4’) Remove gaps between the cubes (actually, they were never needed for the construction, but were shown in Fgures 1-4 to clearly illustrate the arrangement). This is stage-1 Menger sponge.

lu1871jkte47 tmp 141e0ebe810d01ef

  1. Now, arrange 20 stage-1 Menger sponges in the same manner as the initial cubes have been arranged. This is stage-2 sponge. If you prefer, you can also alternatively think of the stage-2 sponge as resulting from the replacement of each cube in Figure 4 with a stage-1 sponge.


lu1871jkte47 tmp 70dce71b76587161

  1. Repeat Step 5 of the construction recursively a least one more time. Don’t go too far! The number of sub-cubes and their faces grows very fast (exponentially)!


lu1871jkte47 tmp c860388d3edf8f82

6’) Again, gaps in Figure 6 have only been added for illustrative purposes. The actual Menger sponge does not have them.


Your assignment has two parts:

  1. Write a program that generates and makes it possible to view the Menger sponge using the traditional Open GL. Use different colors (or shades of gray) to visualize faces with different orientations. Make it possible to explore the three-dimensional structure of the sponge by rotating it and zooming in and out (using a mouse). Make it possible to change the depth of recursion and to choose between parallel and perspective projection using a menu. The program should properly redisplay the sponge after the window has been resized. The image should then be resized as well.

  1. Bonus:

    1. Keep the aspect ratio while resizing the window (1% of the final mark).

    2. Implement shading as an optional alternative to rendering the sponge using differently colored faces. Use menu to select the type of rendering (fixed-colored faces vs. shading). (1% of the final mark)

  1. Reimplement Part 1 using core OpenGL