1.3. Second example: Getting three-dimensional - Fractal cuboids

The snowflake curve is a two-dimensional curve. This is because we have only used rotations RU about a single axis, namely the y-axis of the three-dimensional coordinate system. In this way we cannot leave the two-dimensional x-z-plane. Nevertheless, the curve was drawn in a three-dimensional world. To see this, you may want to modify the snowflake by the inclusion of rotations about the x- or z-axis which are called RL and RH. For example, add a rotation RH about the z-axis as in

    F(x) ==> F(x/3) RU(-60) RH(20) F(x/3) RU(120) F(x/3) RU(-60) F(x/3);

Afterwards, invoke the rules by a click on derivation for a number of times: Do you see how the curve extends into three dimensions? If not, click on the button above the 3D view, keep the mouse button pressed and move the mouse. This rotates the virtual camera so that you can see the curve from another perspective.

In any case, since the snowflake is designed as a two-dimensional curve, the extension to three dimensions looks somewhat odd. So let's consider a new example, fractal cuboids. Click here to load the cuboids and here to apply the replacement rule of the example.

The cuboids example uses two new turtle commands: Box(x, true) draws a box (a cuboid) having length x (true means that the faces of consecutive boxes adjoin), and Scale(x) scales the following symbols in size by a factor of x. The initial cuboidal structure is created by the replacement rule

Axiom ==>
    Scale(1)
    RU(90) Box(L, true)
    RH(-90) RU(-90) Box(L, true)
    RH(90) RU(-90) Box(L, true)
    RH(-90) RU(-90) Box(L, true) Box(L, true)
    RH(90) RU(-90) Box(L, true) Box(L, true)
    RH(-90) RU(-90) Box(L, true) Box(L, true)
    RH(90) RU(-90) Box(L, true) Box(L, true)
    RH(90) RL(-90) Box(L, true);

This rule is part of the special method init: This method is invoked automatically by GroIMP and, thus, should contain instructions to initialize the structure.

The length of the boxes is specified by a constant named L. Such a constant has to be declared in the RGG source code. In this example the declaration is simply

const int L = 2;

int is the type of the constant, where int stands for integral numbers. Every type of the Java programming language can be used. Other types are, e.g., float for single-precision floating-point numbers, double for double-precision floating-point numbers, or String for character sequences.

The development of the fractal cuboids is implemented by two rules contained in the method derive. The first rule is responsible for the structural development:

Box ==> Box(L, true) RU(90) ... Box(L, true);

It works similarly to the rule of the previous example which implemented Koch's construction step. Every box (ignoring its length parameter) is replaced by a sequence of boxes and rotations.

The second rule is responsible for the overall size of the structure: In order to keep this size constant, a scaling of all boxes to one third of their previous size is necessary in each step. This can be achieved globally for all boxes by the rule

Scale(x) ==> Scale(x/3);

This is a difference to the Koch example, where each F was individually reduced in size.