yet another blog about computer, technology, programming, and internet

Saturday, April 19, 2008

Modeling a Tree using L-System

Saturday, April 19, 2008 Posted by Ismail Habib , 29 comments
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]



29 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
  9. Anonymous8:03 PM

    This info is priceless. Where can I find out more?

    Also visit my site ... how to carrier unlock samsung galaxy s4

    ReplyDelete
  10. hello, nice work :) , i have question , did you use glRotatef et PushMatrix and PopMatrix() ??

    ReplyDelete
  11. Thanks a lot for publishing this. I had fun recreating your Tree C in Minecraft (with different parameters, and with leaves once the branches got small enough). Screenshot is here: http://www.instructables.com/id/Python-coding-for-Minecraft/ . And python source code is here: https://github.com/arpruss/raspberryjammod/tree/master/python2-scripts/mcpipy (see lsystem.py).

    ReplyDelete
  12. When I try to render your Tree C, it looks good when I apply the two rules sequentially (but then they are equivalent to a single rule), but if I follow the proper L-system way and apply them simultaneously, I get something that looks to me quite different (and not as good). In my above comment things worked out OK because by mistake my l-system code was applying rules sequentially.

    ReplyDelete
  13. Can I have the code for it ?

    ReplyDelete