simulating trees with fractals and l-systems eric m. upchurch cs 579

21
Simulating Trees Simulating Trees with Fractals with Fractals and L-Systems and L-Systems Eric M. Upchurch Eric M. Upchurch CS 579 CS 579

Post on 15-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Simulating Trees Simulating Trees with Fractals and with Fractals and

L-SystemsL-SystemsEric M. UpchurchEric M. Upchurch

CS 579CS 579

Page 2: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Background - FractalsBackground - Fractals

Fractals are recursive, self-Fractals are recursive, self-similar structuressimilar structures Infinitely detailed – zooming in Infinitely detailed – zooming in

reveals more detailreveals more detail Similar, though not necessarily Similar, though not necessarily

identical, at any level of identical, at any level of magnificationmagnification

Generated using a variety of Generated using a variety of methods, such as IFS and L-methods, such as IFS and L-SystemsSystems

Many natural forms display Many natural forms display fractal geometry (like trees!)fractal geometry (like trees!)

Page 3: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Background – L-SystemsBackground – L-Systems Formal grammar developed by Aristid Formal grammar developed by Aristid

Lindenmayer as a theoretical framework for Lindenmayer as a theoretical framework for studying development of simple multicellular studying development of simple multicellular organismsorganisms

Subsequently applied to investigate higher Subsequently applied to investigate higher plantsplants

Uses rewriting rules (productions) to grow a Uses rewriting rules (productions) to grow a string or systemstring or system

Productions are applied in parallel (unlike Productions are applied in parallel (unlike Chomsky grammars)Chomsky grammars) This is motivated by biological considerations – This is motivated by biological considerations –

this is how living organisms growthis is how living organisms grow

Page 4: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Simple L-SystemSimple L-System Strings built of letters Strings built of letters aa

and and bb Each letter is associated Each letter is associated

with a with a rewriting/production rule:rewriting/production rule: a a ab ab b b a a

Rewriting starts from an Rewriting starts from an axiomaxiom, a starting string (b , a starting string (b in this case)in this case)

Each production is Each production is applied simultaneously in applied simultaneously in each stepeach step

Page 5: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

L-Systems – Properties L-Systems – Properties

Can be context-free or context-sensitiveCan be context-free or context-sensitive Different production rules for the same Different production rules for the same

symbol based upon neighboring symbolssymbol based upon neighboring symbols If run repeatedly and interpreted as If run repeatedly and interpreted as

images, can produce fractal geometryimages, can produce fractal geometry Can describe many “traditional” fractal Can describe many “traditional” fractal

patterns, such as Koch curves and patterns, such as Koch curves and constructionsconstructions

Can describe & produce very complex Can describe & produce very complex fractal patternsfractal patterns

Page 6: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Iterated Function Iterated Function SystemsSystems

An IFS is any system which recursively An IFS is any system which recursively iterates a function or a collection of arbitrary iterates a function or a collection of arbitrary functions on some base objectfunctions on some base object

An IFS can be used to generate a fractal An IFS can be used to generate a fractal patternpattern

The IFS fractal is made up of the union of The IFS fractal is made up of the union of several copies of itself, each copy being several copies of itself, each copy being transformed by a function transformed by a function No restriction on transformations, though they No restriction on transformations, though they

are usually affineare usually affine Can use deterministic or stochastic processesCan use deterministic or stochastic processes

Page 7: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Iterated Function Iterated Function SystemsSystems

If the system is made up by k If the system is made up by k functions (or transformations) {ffunctions (or transformations) {fii(x) | (x) | 1 < i < k} and iterated 1 < i < k} and iterated nn times on the times on the base set base set bb, then the IFS is defined as , then the IFS is defined as the set: the set: { f{ fi1i1(f(fi2i2 ( .. f ( .. fikik(b) .. )) | for all i(b) .. )) | for all ijj, with 1 , with 1

< i< ijj < k, j = (1, 2, .. , k) } < k, j = (1, 2, .. , k) }

In the limit that In the limit that nn becomes infinite, becomes infinite, an IFS becomes a fractal. an IFS becomes a fractal.

Page 8: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Relationship of IFS to L-Relationship of IFS to L-SystemsSystems

Both are recursive in natureBoth are recursive in nature Both can be used to produce fractalsBoth can be used to produce fractals L-Systems are, arguably, a L-Systems are, arguably, a

specialized form of IFS, whose specialized form of IFS, whose functions are specified by the functions are specified by the production rules of the grammarproduction rules of the grammar Replace the formal grammar of an L-Replace the formal grammar of an L-

System with functions/transformations, System with functions/transformations, and you have an IFSand you have an IFS

Page 9: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Describing TreesDescribing Trees

A A rooted treerooted tree has edges that are has edges that are directed and labeleddirected and labeled

Edge sequences form paths from a Edge sequences form paths from a distinguished node, called the distinguished node, called the rootroot or or basebase, to , to terminal nodesterminal nodes In biological sense, these edges are In biological sense, these edges are branch branch

segmentssegments A segment followed by at least one more

segment in some path is called an internode A terminal segment (with no succeeding

edges) is called an apex

Page 10: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Axial TreesAxial Trees Special type of Special type of rooted treerooted tree At each node, at most one outgoing straight

segment is distinguished All remaining edges are called lateral or side

segments. A sequence of segments is called an axis if:

the first segment in the sequence originates at the root of the tree or as a lateral segment at some node

each subsequent segment is a straight segment the last segment is not followed by any straight

segment in the tree. Together with all its descendants, an axis

constitutes a branch. A branch is itself an axial (sub)tree.

Page 11: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Axial TreesAxial Trees

Axes and branches are ordered The root axis (trunk) has

order zero. Axis originating as a

lateral segment of an n-order parent axis has order n+1.

The order of a branch is equal to the order of its lowest-order or main axis

Page 12: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Example Axial TreeExample Axial Tree

Page 13: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Honda’s ModelHonda’s Model Limited model with following assumptions:Limited model with following assumptions:

Tree segments are straight and their girth is not considered A mother segment produces two daughter segments through

one branching process Lengths of the two daughter segments are shortened by

constant ratios, r1 and r2, with respect to the mother segment

Mother and daughter segments are contained in the same branch plane. The daughter segments form constant branching angles, a1 and a2, with respect to the mother branch

Branch plane is fixed with respect to the direction of gravity so as to be closest to a horizontal plane. An exception is made for branches attached to the main trunk, where a constant divergence angle α between consecutively issued lateral segments is maintained

Page 14: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Honda’s GeometryHonda’s Geometry

Page 15: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Honda’s TreesHonda’s Trees

Page 16: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

My Tree SimulatorMy Tree Simulator Written in C++, using the DirectDraw APIWritten in C++, using the DirectDraw API Draws 2D trees by writing to a bitmapDraws 2D trees by writing to a bitmap Does simple lighting and shadingDoes simple lighting and shading Produces a fair mix of completely ugly Produces a fair mix of completely ugly

trees and good looking/accurate treestrees and good looking/accurate trees Uses stochastic IFS transformations, Uses stochastic IFS transformations,

inspired from L-Systems and extends inspired from L-Systems and extends Honda’s workHonda’s work

Drawing infrastructure borrowed from a Drawing infrastructure borrowed from a Julia Set generatorJulia Set generator

Page 17: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

My Tree SimulatorMy Tree Simulator

A tree is specified by:A tree is specified by: Radius (thickness of trunk)Radius (thickness of trunk) HeightHeight Some number of branches, each having:Some number of branches, each having:

Scaling factor (all branches are scaled Scaling factor (all branches are scaled according to order)according to order)

Height/length of branchHeight/length of branch Lean angle (from higher order branch)Lean angle (from higher order branch) Rotation angle (around higher order branch)Rotation angle (around higher order branch)

Number of branches is used in recursively Number of branches is used in recursively creating branchescreating branches

Page 18: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

My Tree SimulatorMy Tree Simulator

IFS is performed by transformations IFS is performed by transformations specified in each branch.specified in each branch. Transformations: scale, lean, rotation, Transformations: scale, lean, rotation,

are stochastically determinedare stochastically determined Foliage is done using the same Foliage is done using the same

method but using different colors to method but using different colors to give the illusion of leavesgive the illusion of leaves

Z-buffer utilized for determining Z-buffer utilized for determining which pixels are drawnwhich pixels are drawn

Page 19: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

My Tree SimulatorMy Tree Simulator A tree contains several flags that define A tree contains several flags that define

which IFS transformations are applied:which IFS transformations are applied: Use Branch Heights Use Branch Heights If true, places branches If true, places branches

randomly up trunk. If false, places all branches randomly up trunk. If false, places all branches coming out of trunk (and recursive branches) at coming out of trunk (and recursive branches) at same point. same point.

False tends to make trees more irregular. False tends to make trees more irregular. Global Scaling Global Scaling If true, scales branches and If true, scales branches and

foliage based on a single scale (stored in the trunk foliage based on a single scale (stored in the trunk branch). Otherwise, scales each branch separately branch). Otherwise, scales each branch separately based on a scale stored per branch. based on a scale stored per branch.

True makes trees more regular, and “tighter”. True makes trees more regular, and “tighter”. False makes trees more irregular, but can cause False makes trees more irregular, but can cause

“puffiness”“puffiness”

Page 20: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

My Tree SimulatorMy Tree Simulator

Scale By Height Scale By Height If true, branches and If true, branches and foliage decrease (more dramatically) as foliage decrease (more dramatically) as their height increases.their height increases.

True keeps some trees from getting too “puffy”. True keeps some trees from getting too “puffy”.

False makes trees more top-heavy, fuller, like False makes trees more top-heavy, fuller, like elms. elms.

True makes trees slimmer and decreasing, like True makes trees slimmer and decreasing, like a willow bush. a willow bush.

True will give a younger looking tree, false will True will give a younger looking tree, false will give an older looking tree with the same give an older looking tree with the same structure. structure.

Page 21: Simulating Trees with Fractals and L-Systems Eric M. Upchurch CS 579

Future WorkFuture Work

Convert to 3DConvert to 3D 2D representation is easier, but 2D representation is easier, but veryvery

limitinglimiting Allow model exportation for placement into Allow model exportation for placement into

virtual worldsvirtual worlds Use foliage models in 3DUse foliage models in 3D

More realistic effect, scales well, could More realistic effect, scales well, could provide physics-based modeling effects provide physics-based modeling effects (wind, sway, etc)(wind, sway, etc)

Enhance parameterization of treesEnhance parameterization of trees Currently, everything is random!Currently, everything is random!