Saturday, April 19, 2008

Modeling a Tree using L-System

An L-system or Lindenmayer system is a parallel rewriting system, namely a variant of a formal grammar (a set of rules and symbols), most famously used to model the growth processes of plant development, but also able to model the morphology of a variety of organisms. [wikipedia]

When using this model, we have to define a set of grammar rules that will be used to describe the growth of the branches of a tree. The rules that we define will later be implemented as the growth of the tree in an iterative fashion. In this system, we define these following alphabets that will be used in the production rules:

f : create branch
l : create leaf
[ and ]
: define a set of local area/branch. The definitions of the area are put inside the [ and ]

+ and -
: rotate the branch right/left in x-axis

^ and v
: rotate the branch up/down in y-axis

<>
: twist the branch left/right in z-axis


By using the symbols above, we can begin to create a tree with our system. But before that, we also have to define several properties that are also important in generating the tree, which are:
  • The number of production rules iterations, for determining the level of the branches,
  • The angle, for determining branch curves, and
  • The radius of the branches and the decreasing value of it, in an iterative way The length of the branches

The following are several examples of the production rules that are used using the system:

Tree A

Angle : 25
# Iterations: 6
Branch radius: 0.02
Branch radius reduction: 0.0015
Branch length (height): 0.15
Initial value : fffffA
Production rules : A = f[++Al][--Al]>>>A




Tree B

Angle : 30
# Iterations: 10
Branch radius: 0.01
Branch radius reduction: 0.001
Branch length (height): 0.16
Initial value : fA
Production rules : A = f[^Bl]>>[^Bl]>>A, B = f[-
Bl]B


Tree C

Angle : 15
# Iterations: 13
Branch radius: 0.02
Branch radius reduction: 0.0015
Branch length (height): 0.15
Initial value : fA
Production rules : A = ^fB>>>B>>>>>B, B = [^^f>>>>>>A]



9 comments:

  1. Simple but nice production rules iterations. Very good blog. All the best!

    ReplyDelete
  2. thank you for the compliment :)

    ReplyDelete
  3. Anonymous11:28 PM

    Did you use c++ to code ???

    ReplyDelete
  4. Yes, I do use C++ and OpenGL.

    ReplyDelete
  5. Anonymous6:20 PM

    i am trying to make a 2d tree without leaves. something very simple to start with in c++. can you point me to any tutorial i can see examples of such things?

    ReplyDelete
  6. Anonymous1:54 AM

    hello, is it possible to have the source for one of these trees?

    ReplyDelete
  7. Thanks for posting this! I was too bored but now I'll try to design this tree. Keep posting.

    ReplyDelete
  8. Hello, could you please share the source code also? thanks

    ReplyDelete