Home | News | Hacking | Sciences | Technology | Ti 92 | Programming | Free articles | Links | Webmaster |
||||||||||||||||||||||||||||||||||||||

## SIMULATION OF PLANTS |
||||||||||||||||||||||||||||||||||||||

## 1. Introduction
## 2. The Idea Behind L-Systems
The beauty of this L-system is, that it is extremely
simple. There are only two different elements (in this example represented
by the blue and the red line) : the red line represents the younger parts
of the plant, while the blue line represents the older part of the plant.
It is therefore quite reasonable to start with the younger part (i.e. use
the red line as axiom). The first reproduction rule (the one for the red
line) states, that with each iteration the young part grows by a factor of
two and becomes an old part (the red line is replaced by two blue lines).
Additionally three new young branches (the three red lines) grow from this
old part. The second reproduction rule tells, what happens to old parts:
they simply grow, but no new branches are formed (one blue line is
replaced by two blue lines). This behaviour is also what you would expect
from a real plant: it is highly unlikely that after some time a new leave
emerges from the stem of an old tree - the probability that the leaves
starts at some new branch is much higher.
In the image above I have drawn the red and blue lines as green, so that
it reminds a bit more to a plant. The starting point (n=0) is just the
axiom (i.e. a straight line corresponding to the red line of the axiom
which represents the new part of the grass). In the first iteration (n=1)
the replacement rule for the red line is applied (there is no blue line,
that could be replaced because the axiom was only one single red line) and
we get an old stem from which 3 young branches emerge. In the second
iteration (n=2) the two blue lines of the stem are replaced by 4 blue
lines (i.e. the old stem grew) and each branch is replaced by a stem from
which 3 new branches emerge. If you do this for another 6 iterations you
end up with something that looks pretty similar to some sort of grass. - it starts with a young part (axiom: red line)
- each young part becomes old but while it becomes old it produces 3 young branches
- old parts can still grow, but don't produce any branches
However if you really want to generate these plants on your computer,
you have to use a little bit more formal aproach (although the colorful
lines look nice, the computer is usually not to happy with them ;-)
Lindenmayer suggested to represent each different element of the plant by
a different letter (for example the red line would be represented by F and
the blue one by G). To represent the actual branching structure you need
additionally some geometrical representation. Lindenmayer sugested to use
turtle graphics for this representation. Originally turtle graphics has
been used in an old programming language (called LOGO), that probably most
of us haven't seen any more. Nevertheless the idea behind is very
intuitive and most people will recognize it immediately because many games
use it to control the movements of the actors or some rendering programs
use it also for their realtime preview. derivation length: 8 Beside the actual L-system there are a few additional informations needed on how the L-system has to be interpreted. In the L-system above we have to specify the angle by which the orientation is changed with + or -. As you can see this affects the final result quite significantly:
## 3. Symbols used in L-SystemsThe symbols mentioned above are already a good starting point, but if you want to create more complex models (3D models, flowers,...) you need a little bit more symbols. In the following list you can find the most important symbols for L-systems with a short description of each (see also the paper "Visual models of plant growth" from Prusinkiewicz et al.): ## Symbols that cause the turtle to move and draw:
## Symbols that control turtle orientation in space:
## Symbols for modeling structures with branches:
## Symbols for creating and incorporating surfaces:
## Symbols that change the drawing attributes:
The rotation matrices mentioned in the above definitions are defined as follows: The definitions above represent the symbol definitions according to Lindenmayer (and extended by Prusinkiewicz). It is a good idea to use these definitions for your own implementations too, because it is much easier this way to exchange the L-systems with fellow programmers/scientists.
## 4. Let's start growing ...Well now you know everything you need to let the plants grow on your
desktop. When you want to actualy grow plants now, you have to either
implement the string replacement and graphic output routines or you can
use one of the available programs. The best programm you can use is
LinSys3D
developed by Andrea Esuli.
derivation length: 8 //the number of derivation steps Axiom: F //the axiom F --> G[+F][-F]GF //one (or more) productions G --> GG Additionally to the actual L-system you need some parameters for the graphical interpretation. For the L-system above, these are: angle increment: 15 //the turning angle, in degrees initial line width: 1 pixels //… self-explanatory initial color: 2 //index to the color map (2=green) scale factor: 0.9000 //controls the size on the screen The commands above will produce the simple gras we discussed earlier. By modifying the code above you can easily represent any L-system you want.
## 5. Parametric L-Systems
As we have seen L-systems are a very powerfull tool to model plants.
Nevertheless I have to admit that finding a proper model for a certain
plant is usually quite time consuming (at least for non-biologists like me
;-) When you want to model a new plant you should have a couple of photos
(or even better: the plants itself) in different growth phases. Then you
have to compare from which part which other parts are developed and then
you can asign to each element a letter and you must try to find the rules
that govern the development. Additionally you should try to keep the axiom
as simple as possible (don't put all your knowledge into the axiom - the
axiom should not be the final plant but the seed for the plant! ). If you look at the final plant it is usually much to
complex to get a good idea on how to design the L-system. Therefore you
should try to get a few images of the plant as it looks in an early state.
There is also another principle, that might help you sometimes:
selfsimilarity. Put simply, this means that if you take a small part of
the plant, the structure will be similar to the structure of the entire
plant (this principle has been discussed very extensively in the context
of fractals).
Based on what we know so far, the most obvious approach would be something like this: Axiom: F F --> FF[+FFFF][-FFFF]FF[+FFF][-FFF]FF[+FF][-FF]FF[+F][-F]FFFF Sure this type of L-system would reproduce the leaf above, but as you
might guess it is not very desireable to put all your knowledge in one
universal super reproduction rule. The development should be governed by
some simple principles. If we take a closer look at the leaf above, we
see, that the lower branches could be described as older parts, that had
more time to grow, while the upper branches are the newer ones. Of course
this could also be implemented with the ideas we have discussed so far
(just use a couple of different letters for the different growth phases). Lsystem: 0 derivation length: 30 Axiom: A(0) A(d) : d>0 --> A(d-1) A(d) : d==0 --> F(1)[+A(4)][-A(4)]F(1)A(0) F(a) --> F(1.25*a) endlsystem On the first glance this might look a bit confusing, but on the second
glance you'll see, that it is much simpler and more elegant than the brute
force approach above. As we would do in the classical case, we introduce
two different letters for the two different parts we have in the plant -
the old parts, which are just growing straight but are not capable of
making any new branching strucutres (represented by F) and the young
parts, that are responsible for the branching (represented by F). If we simulate this L-system we get the following image: As you can see this image looks already pretty similar to a fern. Nevertheless the spacing between the leaves is a little to big. If we therefore reduce the growth factor from 1.25 to say 1.23 we get a more realistic picture: The corresponding L-system would be: derivation length: 30 Axiom: A(0) A(d) : d>0 --> A(d-1) A(d) : d==0 --> F(1)[+A(4)][-A(4)]F(1)A(0) F(a) --> F(1.23*a) and as viewing parameters I used the following (in L-Studio again): angle factor: 15 initial color: 3 initial line width: 1 I hope that this tutorial gives you a starting point for
your own experiments with L-systems and helps you creating your own plant
simulations. In another tutorial we will discuss the more advanced aspects
of L-systems (i.e.: how can we create asymmetrical plants? How can we
avoid, that all the plants of one type look identical? How can we simulate
environmental influences on the plant? ...). When you have created a good plant and you would like to share your work with others, send your L-system (including the viewing parameters) and I will add it here. |