L System Node Rewrite Example

This is my first post on the stack thread. I recently started reading a book called Algorithmic Beauty of Plants, where in Chapter 1 he explains the L system (you can read the chapter here ).

So, I understand that there are two types of L-systems. Edge rewriting and Node.

Edge editing is relatively straightforward. There is an original starter polygon and alternator. Each edge (side) of the original polygon will be replaced by a generator.

But this rewrite of Node is very confusing. From what I've gathered, there are two or more rules, and each iteration replaces the variables in the rules with their constant counterparts.

With the interpretation of turtles, these are standard rules.

F : Move turtle forward in current direction (initial direction is up)
+ : rotate turtle clock wise
- : rotate turtle anti clock wise
[ : Push the current state of the turtle onto a pushdown operations stack. 
    The information saved on the stack contains the turtle’s position and orientation, 
    and possibly other attributes such as the  color and width of lines being drawn.
] : Pop a state from the stack and make it the current state of the turtle

      

So let's take a look at the example shown on this website. http://www.selcukergen.net/ncca_lsystems_research/lsystems.html

Axiom     : FX
Rule      : X= +F-F-F+FX 
Angle     : 45

      

so (ignore the X-axiom) at n=0

its just F, which means a straight line pointing up.

at n=1

replace X in the axiom with the rule

F + FFF + F (ignoring X again)

conclusion is

http://www.selcukergen.net/ncca_lsystems_research/images/noderewrite.jpg

      

a simple example with one rule is fine. but there are some rules in the book Algorithmic Beauty of Plants on page 25 that I'm not sure how to interpret.

X
X = F[+X]F[-X]+X
F = FF

      

See this image.

https://lh6.googleusercontent.com/g3aPb1SQpvnzvDttsiiBgiUflrj7R2V29-D60IDahJs=w195-h344-no

      

at n=0

just "X". not sure what that means

at n=1

applying rule 1 (X-> F [+ X] F [-X] + X) : F [+] F [-] + ignoring all X. it's just a straight line.

by applying rule 2 (F-> FF) : FF [+] FF [-]. it's just a straight line.

The end result should be a turtle moving upwards four times for my understanding. Or, at most, the final output should only contain four lines.

I found an online L-system generator which I thought would help me understand this better, so I entered the same values ​​and this is how the output looks like n = 1

https://lh6.googleusercontent.com/-mj7x0OzoPk4/VK-oMHJsCMI/AAAAAAAAD3o/Qlk_02_goAU/w526-h851-no/Capture%2B2.PNG

      

the output is definitely not a straight line and the worst part has 5 lines which means there should be 5 F in the final output equation.

Help me understand this Node. Without realizing this, I cannot read further in the book.

Sorry for the long post and the links in the pre tag. I cannot post more than two links. Thank you for having the patience to read it from top to bottom.

+3


source to share


1 answer


L systems are very simple and rely on text substitutions.

With this initial information:

Axiom     : FX
Rule      : X= +F-F-F+FX 

      

Then, basically, to create the next generation of the system, you take the previous generation, and for each character in it you apply replacements.

You can use this algorithm to generate the generation:

  • For each character of the previous generation:
    • Check if we have a wildcard rule for this character
      • YES: add replacement
      • NO: add original character

Thus:

n(0) = FX

            +-- from the X
            |
        v---+---v
n(1) = F+F-F-F+FX
       ^
       +- the original F

      

If you had this beginning then:



Axiom : ABA
Rule  : A = AB

      

Then you will have the following:

        +--------+
        |        |
n(0) = ABA       |
       | |       |
       | ++      |
       |  |      |
       vv vv     |
n(1) = ABBAB     |
         ^       |
         +-------+

      

Basically:

  • For every A in X generation on X generation + 1 AB output
  • For every other character without a rule, just output that character (this handles all B letters)

This will be a system that doubles the length for each generation:

Axiom : A
Rule  : A = AA

      

will create:

n(0) = A
n(1) = AA
n(2) = AAAA
n(3) = AAAAAAAA

      

+4


source







All Articles