Interactive Moving Fractal Tree

Español

User guide: 

1. Drag: to rotate the entire figure.

2. Single-left-click: to increase the number of branches.

3. Single-right-click: to decrease the number of branches.

4. Double-click: to switch between:

  • 2-D moving branches,
  • 3-D fixed branches, and
  • 3-D fixed planes

If you cannot see this applet, please install Java

In the 2-D Fractal Tree, the branches can rotate individually.

In the 3-D Fractal Tree , they can not because they collide.

Tree Poem

Source code:

MovingFractalTreeAntiAlias.java

If you know the way to convert this app to one that works on a smartphone or tablet from this source, please let me know:

josechu2004@gmail.com

Even if you cannot see the Java Applet above, probably you can run the following Java .jar app.  It does exactly the same (except that it is 4 times the size) The size is very easy to change in the embedded file: MovingFractalTree.ini

MovingFractalTreeAntiAlias.jar

The .class Applet has been converted to .jar with Raja Ranjan's applet2app.jar tool.

 

A little of history:

The idea of the 2-D static tree came to the mind of the author in around 1967, when he was six.  The figure was intriguing to him and he used to sketch it on his school notebooks.  Of course with not very precise proportions.

Fifteen years later, in 1982, after having read a mathematical essay in the university's library, the author analyzed it thoroughly and found in awe its fractal properties (if the length of the branches of the same generation decreased following very simple rules the tree would fill the plane! and without two branches ever touching one another!).

This was a big surprise to him and his interest in the world of fractals started to grow.  The same year (1982), he asked to himself if a 3-D version of the tree where the branches would reach every point in space without ever overlapping could exist.  When he found that this object also existed he was fascinated and appreciated, once more, the beautiful structure of mathematics.

These two static objects, the 2-D tree and 3-D tree, were published in the magazine "Cacumen" in 1984.

In 1984 the author hadn't noticed yet that, in the 2-D tree, every branch could rotate in space independently and freely about its "father branch" and that the branches would never collide one another even if the starting 2-D tree had millions (or infinite) branches.  He found that in 1987.  That year, after a thrilling lapse of nightly inspiration, the static version of the 2-D fractal tree became a moving fractal.

It took him some time to realize that, opposite to what happened to the 2-D tree, the 3-D tree did not have this moving possibilities because the branches would collide one another.

For years, the moving fractal only moved in the head of the author, the computer program to see the 2-D tree in movement wouldn't come until ten years later.  He still needed a key information:  in April 1997 he asked in the sci.math Usenet newsgroup what was the mathematical formula to rotate an arbitrary point around an arbitrary axis in 3-D space.  Pertti Lounesto's precise answer at the end of this thread on Tue Apr 29 1997 was the key that let us to visualize the tree rotating on the computer's screen that very day.

---

Look here how to rotate an arbitrary point in space about an arbitrary axis (In Spanish for now).

And here to study how to draw an object in perspective onscreen (also in Spanish for now).

---

MSDOS Version:

Now, the current old (but with different features) MSDOS version of the program to rotate and visualize the moving fractal tree:

Please note that MSDOS programs may not fully work in modern PCs with default configuration.

It includes the executable and the source code in QuickBasic 4.5. 

The source was compiled with the QuickBasic clone: "Power Basic 3.1" to improve its speed. 

Download the program here: arbol209.zip (44 KB), decompress the executable, run it and press the space bar to see it in action.

Added in 2017-02-27, arbol209.zip doesn't work in new Windows versions, but the next, compiled with QB64 as is, does: ArbolQB64.zip (605 KB)

Here is the program main screen:

mft_screen.gif (8927 bytes)

arbol.exe main screen

As you can see, every branch has two sons, four grandsons, eight great-grandsons... and so on.

The tree has several interesting properties:

  • No matter how deep you draw branches, they never overlap one another.
  • If you drew an infinite number of branches, they'd fill the plane (never overlapping).
  • All the branches can rotate simultaneously without overlapping*, as can be seen in the pictures below.  (Every branch can rotate freely, being the rotation axis its father branch.)

The only condition for these properties to work is that the length of any branch has to be half of the length of its grandfather branch.

* The program has also a 3-D option that allows you to draw a space filling tree.  In 3-D, the branches self-overlap when they rotate, so you couldn't build a physical moving model of it, although you could build a static model.  All of the pictures below come from the 2-D tree, from which you can build a model, even a moving model.

 

 

A Point Rotating Around an Axis

To program a tree which rotates you need to know how to rotate an arbitrary point around an arbitrary axis in 3-dimensional space:

Let be (Ax , Ay , Az) and (Bx , By , Bz) two points that define an axis and (Px , Py , Pz) the point.  P ’ is the point P  after rotating it "a" radians around the axis.

Let n be the unit vector pointing from A to B:

Then (using 3D vectors):

Note the dot and cross products in this formula are not standard products, but scalar and vector ones.
Note the
± sign is because P’ could rotate in two opposite directions.

From this formulas you can obtain the rotating MSDOS code in the next section:

 

The Code

With this simple piece of code (in QuickBasic, PowerBasic or QBasic), anyone can create, draw and see the tree rotating randomly:

REM Initialization
SCREEN 12
S = 10
WINDOW (-S, -S)-(S, S)
REM NIter is the number of iterations
NIter = 12
TPoints = 2 ^ NIter
Length = S / 2
Stp = TPoints / 4
K = 1 / SQR(2)
REM a(x, y)holds the coordinates of every branch tip
DIM a(TPoints, 2)

REM Calculate plain tree
FOR i = 1 TO NIter - 1
  FOR x = Stp TO TPoints STEP Stp * 4
    IF i MOD 2 = 0 THEN
      a(x, 0) = a(x + Stp, 0)
      a(x + 2 * Stp, 0) = a(x + Stp, 0)
      a(x, 1) = a(x + Stp, 1) - Length
      a(x + 2 * Stp, 1) = a(x + Stp, 1) + Length
    ELSE
      a(x, 0) = a(x + Stp, 0) - Length
      a(x + 2 * Stp, 0) = a(x + Stp, 0) + Length
      a(x, 1) = a(x + Stp, 1)
      a(x + 2 * Stp, 1) = a(x + Stp, 1)
    END IF
  NEXT x
  Stp = Stp / 2
  Length = Length * K
NEXT i

di:
CLS
REM Leave the program when pressing any key
IF INKEY$ <> "" THEN END
Stp = TPoints / 4

REM Draw tree
FOR i = 1 TO NIter - 1
  FOR x = Stp TO TPoints STEP Stp * 4
    x0 = a(x, 0)
    y0 = a(x, 1)
    P2 = 2 * Stp
    x1 = a(x + P2, 0)
    y1 = a(x + P2, 1)
    LINE (x0, y0)-(x1, y1)
  NEXT x
  Stp = Stp / 2
NEXT i

Stp = TPoints / 4
Pi = 3.14159
St = Pi / 128

REM Rotate Tree Randomly
FOR i = 1 TO NIter - 1
  Counter = 0
  FOR x = Stp TO TPoints - 1 STEP Stp * 2
    P2 = 2 * Stp
    Counter = Counter + 1
    Ax = a(x, 0)
    Ay = a(x, 1)
    Az = a(x, 2)
    IF Counter MOD 2 = 1 THEN
      Bx = a(x + P2, 0)
      By = a(x + P2, 1)
      Bz = a(x + P2, 2)
    ELSE
      Bx = a(x - P2, 0)
      By = a(x - P2, 1)
      Bz = a(x - P2, 2)
    END IF
    Mn = SQR((Bx - Ax) ^ 2 + (By - Ay) ^ 2 + (Bz - Az) ^ 2)
    nx = (Bx - Ax) / Mn
    ny = (By - Ay) / Mn
    nz = (Bz - Az) / Mn

    Alfa = INT(RND * 8) * St
    IF RND > .5 THEN Alfa = -Alfa
    ca = COS(Alfa)
    sa = SIN(Alfa)

    FOR j = x - Stp + 1 TO x + Stp - 1
      Px = a(j, 0) - Ax
      Py = a(j, 1) - Ay
      Pz = a(j, 2) - Az
      nPEscalar = nx * Px + ny * Py + nz * Pz
      nnPx = nPEscalar * nx
      nnPy = nPEscalar * ny
      nnPz = nPEscalar * nz
      cx = ca * (Px - nnPx)
      cy = ca * (Py - nnPy)
      cz = ca * (Pz - nnPz)

      snxPx = sa * (ny * Pz - nz * Py)
      snxPy = sa * (nz * Px - nx * Pz)
      snxPz = sa * (nx * Py - ny * Px)

      a(j, 0) = nnPx + cx + snxPx + Ax
      a(j, 1) = nnPy + cy + snxPy + Ay
      a(j, 2) = nnPz + cz + snxPz + Az
    NEXT j
  NEXT x
  Stp = Stp / 2
NEXT i

GOTO di


The output of this code after a few random rotations may be like this:

arbol_random.gif (10109 bytes)

Tree under random rotations

 

Program Visual Output

There are other types of rotation that give us curious figures.  If you run the MSDOS program (complete, not the portion of code above) and press the key numbers "4" and "6" eight times each, you obtain:

arbol_oposite.gif (5327 bytes)

Tree under opposite rotations


Experimenting a little more, one can obtain figures like this:

arbol_oposite_2.gif (7138 bytes)

From the fifth iteration, the branches don't rotate

 

On 1999/04/04 the Golden Ratio (or Divine Proportion) = Phi = (sqr(5) + 1) / 2 was introduced.   If you multiply the angle Alfa in the program by Phi in each iteration, you can obtain curving figures like the one below.  (This one can't be obtained with the current version of the MSDOS program "arbol209.zip" nor with the Java applet.)

Multiplying Alfa by Phi on each iteration

 

For further information about Moving Fractal Trees, you can read the article "A TUTORIAL AND RECIPE FOR MOVING FRACTAL TREES" in the magazine Computers & Graphics, Vol 22, Number 2 - 3, pp. 301 - 305, 1998.

You can also read two previous articles about the subject, one in "Carrollia"* (Number 53, pp. 10 - 12, Jun 1997). 

The other was published in the Spanish magazine "Cacumen"** (Number 15, p. 38, Apr 1984).

* Carrollia is published by the Special Interests Group about mathematics within Mensa Spain: "Carrollsig", and is edited by Josep Maria Albaigès.

** Cacumen was a Spanish magazine of Wit, Playing and Humour that died out in December 1986.


If you have any question or comment, contact me at: josechu2004@gmail.com

 

Guestbook

 

First post in: 1997
Last change: 2006-08-07