Sunday, July 24, 2011

L-System Trees

I continued working with the Algorithmic Beauty of Plants book and implemented parametric and context-sensitivity from chapter 1, made the trees from 3D tubes (instead of lines) and tried some of the examples from chapter 2 Modeling of trees. I had some success but couldn’t reproduce some of the models, mainly the section with tri-branching trees.

Here’s my results of the rules on page 56 varied with the parameters on page 57:

p56

And here’s what the original ones from the book look like:

p56original

They look pretty similar, apart from (b). Note that in (b) the height of my version is the same as the other trees, but in the book it is much shorter. This is odd because the table on page 57 modifies the branch contraction rate (r2) only, not the trunk contraction rate (r2) which is always 0.9 so they should all be the same height.

In fact, it’s not clear what the height should be to get the above images as the axiom at the start sets the length to 1 and the width to 10, and if the length:width ratio really were 1:10, the result would be a lot more squat, like this:

JellyEngineXna 2011-07-24 15-10-02-33

And it’s still pretty squat at 10:10:

JellyEngineXna 2011-07-24 15-10-26-57

I found a ratio of 100:10 worked best to yield results similar to the book.

The experiments on page 59 looked pretty much identical to the book (again using a ratio of 100:10 so an initial axiom of A(100,10) instead of A(1,10)), here’s mine:

p59

And here’s the books:

p59original

I had the least luck with reproducing the examples under Ternary branching. In the book (a) is shown as:

image

… which has a degree of irregularity… I don’t know where the model can get this as there is no stochasticity specified and the tropism applied is straight down (like the force of gravity), so why would the branch on the right bow down more than any other branch? My results show a much more regular model:

p60a

The closest of the ternary branching section I got was (b), although I had to fiddle with a few parameters (setting the width increase rate to 1.432 instead of the 1.732 given). Here’s the version in the book:

image

And here’s my result:

p60b vr1.432

(c) and (d) were real headaches… I can’t get these to look anything like the ones in the book… I’m pretty sure something’s missing ar the parameters specified are wrong, especially the elongation rate (lr) for (c); on page 61 it’s defined as 1.790 and all the others are 1.1 or less. Plugging this into my L-System/turtle interpreter results in a very tall tree (looking up at it in the first image and looking head on but zoomed out enough to see whole tree in the second):

JellyEngineXna 2011-07-24 15-38-40-99

JellyEngineXna 2011-07-24 15-39-01-39

I’m pretty sure my coding is right on this one, if you take the start piece from the axiom which is defined as F(200) and apply p2 (F(l) –> F(l*lr) 8 times with lr set to 1.790, this is the same as 200*(1.7908) which is about 21079. For the other trees, lr is 1.109 and the base trunk height after 8 iterations of p2 would be 200*(1.1098) which is about 457. However the image in the book shows the tree as the same height and roughly the same proportion to its width as the other examples:

image

If I muck about with the parameters a bit I can get something that looks a bit more like it:

JellyEngineXna 2011-07-24 15-47-56-31

… but it’s not quite as nice. (d) is the same story really, can’t reproduce it from the parameters given… :(

I’m *pretty* sure I’m right but this book has been out since 1990 and there’s nothing specified in the errata. I tried to find these models in the virtual lab available from algorithmicbotany.org but no luck. So I might fire off an email and see if any one associated with the book can help me out…

Other than that I implemented horizon culling on the planet with a lot of help from an article at crappy coding, redid some of my basic rotation stuff (I had everything mirrored through the z axis), and tried to streamline how new patches are formed on the planet (it didn’t work!). I’m not sure what to do next, had a look at some demoscene programs and am now utterly depressed at how little I’ve done! I might try generating normal maps from the heightmap of a planet patch for lighting, maybe do atmospheric scattering, texturing of the planet and/or trees, adding leaves maybe? Hiring someone else to do this for me?? :)

6 comments:

Tyisha said...

I would be interested in seeing the source code you used. I am learning DirectX and C++ and I am learning about L-systems.

John Leonard said...

Hi Tyisha, sorry for late reply, to be honest my code is very very messy - there's a project on codeplex http://ltrees.codeplex.com/ which is much neater (& faster (& has leaves!)) - but if you still want mine I can send it on

murs said...

John,

I am replying more than a year late, but if it is of any use to you, I was developing my own L-system in JavaScript based on Algorithmic Beauty of Plants. I ended with the same results as you did, so I am pretty sure there is something missing in the book :)

I was worried that my tropism code was wrong, but I applied it to simply Honda trees, and it worked perfectly fine. Which leads me to think that the trees specified in the book have wrong parameters.

John Leonard said...

Hey Murs,

Nice to hear I wasn't the only one! I never got a reply from the authors but that book is so old some of them had retired (or so their autoreply said anyways).

Good luck with your L-system, are you going to stick with plants or try stuff like cities too?

John

murs said...

John,

Oh man, thats tough luck. I am doing this as part of my project at school. Quite enjoying the L-systems actually :) So I might try cities in the future.

I do have a live version running at http://murlax.com/forest which is sort of crude at the moment, but I will be constantly updating it over the next few weeks. Currently it has a Honda tree and an Aano tree with gravitropism implemented. You should be able to view it if you have a WebGL enabled browser. (Code at: https://github.com/muraliavarma/forest_lsystem ). I plan to extend it so that trees compete to grow towards sunlight.

John Leonard said...

Looks good! Keep it up! :)