Engineering Math - Fractal Theory  

 

 

 

Barnsley Fern

Barnsley Fern is a fractal set that looks like a shape of a fern. If you plot this and magnify any one part (e.g, the tip of a leaf) you will see the similar shape of the whole leafs wherever you magnify.

The Barnsley Fern is a well-known example of a fractal, a complex geometric shape that exhibits self-similarity. This means that the fern's structure looks similar at various levels of magnification. It closely resembles the shape of an actual fern plant, with its intricate and repetitive patterns.

The Barnsley Fern is generated using a set of mathematical equations, specifically an iterative process known as an iterated function system (IFS). By repeatedly applying these functions to points on a plane, the image of the fern gradually emerges. Each transformation contributes a specific part to the overall structure, such as the stem, the large fronds, and the smaller leaflets.

One of the fascinating properties of the Barnsley Fern is its self-similarity. If you zoom into a specific part of the fern, for instance, the tip of a leaf, you will find that this small section has the same general shape as the entire fern. This recursive pattern repeats infinitely, making the fern a classic example of fractal geometry.

The Barnsley Fern not only demonstrates the beauty of mathematical constructs but also has practical applications in fields such as computer graphics, where fractals are used to generate natural-looking structures and landscapes efficiently.

Build Up Intuition

Points: 0 FPS: 0 X: 0, Y: 0

This is how you use (play with) this program

Color Scheme Selector

  • Classic Green: Creates a natural-looking fern with varying shades of green
  • Rainbow Gradient: Applies a multi-color effect, with colors changing based on position
  • Monochrome: Uses a single color with different intensities for depth
  • Custom Gradient: Allows you to define your own color transitions

Point Appearance Controls

  • Points/Frame (100-10000):
    • Controls how many points are generated in each animation frame
    • Higher values create denser, more detailed ferns but may affect performance
    • Lower values create sparser ferns but render more smoothly
  • Size (0.5-3.0):
    • Adjusts the size of individual points
    • Larger sizes create a more bold, abstract look
    • Smaller sizes provide more detail and realism
  • Opacity (0.1-1.0):
    • Controls how transparent each point appears
    • Lower values create a soft, ethereal effect
    • Higher values make the fern more solid and defined

Fern Structure

  • Width (0.3-1.1):
    • Modifies the overall spread of the fern
    • Lower values create a narrow, compact fern
    • Higher values produce a wider, more spread-out pattern
  • Curvature (-0.1 to 0.1):
    • Affects the main stem's curve
    • Positive values curve the fern to the right
    • Negative values curve the fern to the left
    • Zero creates a straight stem
  • Randomness (0-0.1):
    • Adds natural variation to the leaflets
    • Higher values create more chaotic, organic patterns
    • Lower values maintain mathematical precision

Probability Controls

These controls determine the frequency of different parts of the fern:

  • Stem (f1Prob):
    • Controls vertical growth
    • Higher values create longer, more pronounced stems
    • Typically kept small (around 0.01) for natural appearance
  • Leaflet (f2Prob):
    • Controls the main leaflet generation
    • Higher values create fuller, more detailed fronds
    • Usually the largest probability (around 0.85)
  • Left (f3Prob):
    • Controls left-side branching
    • Affects the symmetry and density of left-side growth
    • Typically balanced with right probability (around 0.07)
  • Right (f4Prob):
    • Controls right-side branching
    • Affects the symmetry and density of right-side growth
    • Typically balanced with left probability (around 0.07)

Note: The sum of all probabilities must equal 1.0 for proper generation.

Visualization Aids

  • Axes: Displays coordinate system for reference
  • Box: Shows the bounding box of the fern
  • WebGL:
    • ON: Better performance, smoother rendering
    • OFF: Falls back to Canvas rendering (slower but more compatible)

Control Buttons

  • Start/Pause: Controls the generation process
  • Clear: Resets the visualization to start fresh

Real-time Information

The display shows:

  • Total points generated
  • Current rendering speed (FPS)
  • Mouse coordinate position

Tips for Creating Different Fern Styles

  1. Natural Look:
    • Use default probabilities
    • Keep randomness low (0.01-0.02)
    • Use Classic Green color scheme
  2. Abstract Style:
    • Increase point size
    • Use Rainbow or Custom gradient
    • Adjust width and curvature for unique shapes
  3. Dense Pattern:
    • Increase Points/Frame
    • Reduce opacity
    • Adjust leaflet probability higher

How it works ?

The procedure to plot this as follows.

    i) define four sets of 2D transformation equation as follows. (p stands for the coordinate for the current point, m is a 2x2 matrix that is specially created for this transformation, v is 2x1 vector)

      tf1 = m1 . p + v1

      tf2 = m2 . p + v2

      tf3 = m2 . p + v3

      tf4 = m2 . p + v4

    ii) pick any arbitray points (let's say this point is named as p)

    iii) pick one transformation equation out of the 4 equation defined in step i). The probability of the random selection for each transformation equation should be predefined).

    iv) transform p with the transformation equation selected at step iii).

    v) move the current point to the transformed location and set the new position to the current point (p).

    vi) repeat the process iii) ~ v) and plot the point p on the coordinate at each iterations.

Following is the Octave/Matlab code that I wrote as per the procedure described above.

    m1 = [0.85 0.04;-0.04 0.85]; v1 = [0.0;1.60];

    m2 = [0.2 -0.26;0.23 0.22]; v2 = [0.0;1.60];

    m3 = [-0.15 0.28;0.26 0.24]; v3 = [0.0;0.44];

    m4 = [0.0 0.0;0.0 0.16]; v4 = [0.0;0.0];

     

    prob = [0.85 0.07 0.07 0.01];

     

    Np = 50000;

     

    p_old = [0.5;0.5];

     

    pList = [p_old'];

     

    for i = 1:Np

        r = rand();

        if (r < prob(1))

           p_new = m1 * p_old + v1;

        elseif (r < (prob(1)+prob(2)))

           p_new = m2 * p_old + v2;

        elseif (r < (prob(1)+prob(2)+prob(3)))

           p_new = m3 * p_old + v3;

        else

           p_new = m4 * p_old + v4;

        endif;

        pList = [pList;p_new'];

        p_old = p_new;

    end;

Note : the syntax of if statement of Octave may be a little different from Matlab. I tried this only on Octave, so not sure if this code would work in matlab.