CMSC 425: Lecture 11 Procedural Generation: Fractals and L-Systems

Similar documents
CMSC 425: Lecture 12 Procedural Generation: Fractals

Department of Computer Sciences Graphics Fall 2005 (Lecture 8) Fractals

Chapter 8. Fractals. 8.1 Introduction

19.1 The Square Root of Negative One. What is the square root of negative one? That is, is there any x such that. x 2 = 1? (19.1)

FRACTALS LINDENMAYER SYSTEMS. November 22, 2013 Rolf Pfeifer Rudolf M. Füchslin

Fractals and Dimension

Fractals. Justin Stevens. Lecture 12. Justin Stevens Fractals (Lecture 12) 1 / 14

biologically-inspired computing lecture 6 Informatics luis rocha 2015 INDIANA UNIVERSITY biologically Inspired computing

TSP Water Project Report Snowflakes and Fractals

AN INTRODUCTION TO FRACTALS AND COMPLEXITY

LAMC Intermediate Group October 18, Recursive Functions and Fractals

Fractals: How long is a piece of string?

Repeat tentative ideas from earlier - expand to better understand the term fractal.

11. Automata and languages, cellular automata, grammars, L-systems

Hausdorff Measure. Jimmy Briggs and Tim Tyree. December 3, 2016

AN INTRODUCTION TO FRACTALS AND COMPLEXITY

Developmental Models of Herbaceous Plants for Computer Imagery Purposes

Fractal Geometry Time Escape Algorithms and Fractal Dimension

Take a line segment of length one unit and divide it into N equal old length. Take a square (dimension 2) of area one square unit and divide

Fractals. R. J. Renka 11/14/2016. Department of Computer Science & Engineering University of North Texas. R. J. Renka Fractals

Ross Program 2017 Application Problems

What means dimension?

the time it takes until a radioactive substance undergoes a decay

Chapter 6 Animation of plant development

LECTURE 10: REVIEW OF POWER SERIES. 1. Motivation

USING THE RANDOM ITERATION ALGORITHM TO CREATE FRACTALS

Pascal s Triangle Introduction!

Mathematical Modelling Lecture 14 Fractals

Getting Started with Communications Engineering

1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,

INTRODUCTION TO FRACTAL GEOMETRY

Fractals list of fractals - Hausdorff dimension

An Investigation of Fractals and Fractal Dimension. Student: Ian Friesen Advisor: Dr. Andrew J. Dean

1 What is the area model for multiplication?

Lecture Notes on Inductive Definitions

Lecture Notes on Inductive Definitions

M361 Theory of functions of a complex variable

Julia Sets and the Mandelbrot Set

DYNAMICAL SYSTEMS

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

Geometry and Motion, MA 134 Week 1

A LITTLE REAL ANALYSIS AND TOPOLOGY

THE TEACHER UNDERSTANDS THE REAL NUMBER SYSTEM AND ITS STRUCTURE, OPERATIONS, ALGORITHMS, AND REPRESENTATIONS

PHY411 Lecture notes Part 5

Chaos in the Hénon-Heiles system

(Refer Slide Time: 0:21)

Zoology of Fatou sets

Julia Sets and the Mandelbrot Set

Integrating Algebra and Geometry with Complex Numbers

If one wants to study iterations of functions or mappings,

MORE CONSEQUENCES OF CAUCHY S THEOREM

Z-ordering. Reduce n-dim to 1-dim points snake-curve z-ordering bit-shuffling Linear quad trees queries Hilbert curve

MATH 521, WEEK 2: Rational and Real Numbers, Ordered Sets, Countable Sets

Algorithms: Lecture 2

Mechanics, Heat, Oscillations and Waves Prof. V. Balakrishnan Department of Physics Indian Institute of Technology, Madras

Lecture 10: Powers of Matrices, Difference Equations

Math Circles Intro to Complex Numbers Solutions Wednesday, March 21, Rich Dlin. Rich Dlin Math Circles / 27

(pp ) PDAs and CFGs (Sec. 2.2)

Midterm 1 Review. Distance = (x 1 x 0 ) 2 + (y 1 y 0 ) 2.

Chapter 8: Polar Coordinates and Vectors

UNIVERSITY OF TORONTO Faculty of Arts and Science DECEMBER 2011 EXAMINATIONS. MAT335H1F Solutions Chaos, Fractals and Dynamics Examiner: D.

THE TEACHER UNDERSTANDS THE REAL NUMBER SYSTEM AND ITS STRUCTURE, OPERATIONS, ALGORITHMS, AND REPRESENTATIONS

Context-free grammars and languages

+ ε /2N) be the k th interval. k=1. k=1. k=1. k=1

CFGs and PDAs are Equivalent. We provide algorithms to convert a CFG to a PDA and vice versa.

CSE 105 THEORY OF COMPUTATION

B Elements of Complex Analysis

Language-Restricted Iterated Function Systems, Koch Constructions, and L-systems

9th Bay Area Mathematical Olympiad

The Curvature of Space and the Expanding Universe

Algebra 2 End of Course Review

LECTURE 1. 1 Introduction. 1.1 Sample spaces and events

Investigation Find the area of the triangle. (See student text.)

Visualizing complex analytic functions using domain coloring

arxiv: v1 [math.pr] 11 Dec 2017

Designing Information Devices and Systems I Fall 2018 Lecture Notes Note Introduction to Linear Algebra the EECS Way

How to Pop a Deep PDA Matters

0. Introduction 1 0. INTRODUCTION

Vectors and their uses

Infinity Unit 2: Chaos! Dynamical Systems

N M L Nova S. Scotia League. Math. Game One SOLUTIONS

Introduction to Theory of Computing

After taking the square and expanding, we get x + y 2 = (x + y) (x + y) = x 2 + 2x y + y 2, inequality in analysis, we obtain.

2 = = 0 Thus, the number which is largest in magnitude is equal to the number which is smallest in magnitude.

This lecture covers Chapter 5 of HMU: Context-free Grammars

BASICS OF FRACTAL GEOMETRY

CHAOS/FRACTAL

Contents. Counting Methods and Induction

Organization Team Team ID#

The Celsius temperature scale is based on the freezing point and the boiling point of water. 12 degrees Celsius below zero would be written as

LIMITS AND DERIVATIVES

Fractals list of fractals by Hausdoff dimension

(Infinite) Series Series a n = a 1 + a 2 + a a n +...

ACCESS TO SCIENCE, ENGINEERING AND AGRICULTURE: MATHEMATICS 1 MATH00030 SEMESTER / Functions

Natural Language Processing Prof. Pushpak Bhattacharyya Department of Computer Science & Engineering, Indian Institute of Technology, Bombay

(x 1, y 1 ) = (x 2, y 2 ) if and only if x 1 = x 2 and y 1 = y 2.

CMSC 330: Organization of Programming Languages. Pushdown Automata Parsing

Electrical Formulation of the Type Problem: To determine p (r)

UNIT-VI PUSHDOWN AUTOMATA

WA State Common Core Standards - Mathematics

Transcription:

CMSC 425: Lecture 11 Procedural Generation: ractals and L-Systems Reading: The material on fractals comes from classic computer-graphics books. The material on L-Systems comes from Chapter 1 of The Algorithmic Beauty of Plants, by P. Prunsinkiewicz and A. Lindenmayer, 2004. It can be accessed online from http://algorithmicbotany.org/papers/. ractals: One of the most important aspects of any graphics system is how objects are modeled. Most man-made (manufactured) objects are fairly simple to describe, largely because the plans for these objects are be designed manufacturable. However, objects in nature (e.g. mountainous terrains, plants, and clouds) are often much more complex. These objects are characterized by a nonsmooth, chaotic behavior. The mathematical area of fractals was created largely to better understand these complex structures. One of the early investigations into fractals was a paper written on the length of the coastline of Scotland. The contention was that the coastline was so jagged that its length seemed to constantly increase as the length of your measuring device (mile-stick, yard-stick, etc.) got smaller. Eventually, this phenomenon was identified mathematically by the concept of the fractal dimension. The other phenomenon that characterizes fractals is self similarity, which means that features of the object seem to reappear in numerous places but with smaller and smaller size. In nature, self similarity does not occur exactly, but there is often a type of statistical self similarity, where features at different levels exhibit similar statistical characteristics, but at different scales. Iterated unctions and Attractor Sets: One of the examples of fractals arising in mathematics involves sets called attractors. The idea is to consider some function of space and to see where points are mapped under this function. An elegant way to do this in the plane is to consider functions over complex numbers. Each coordinate (a, b) in the real plane is associated with the complex number a + bi, where i 2 = 1. Adding and multiplying complex numbers follows the familiar rules: and (a + bi) + (c + di) = (a + c) + (b + d)i, (a + bi)(c + di) = ac + adi + bci + bdi 2 = (ac bd) + (ad + bc)i. Define the modulus of a complex number a + bi to be length of the corresponding vector in the complex plane, a 2 + b 2. This is a generalization of the notion of absolute value with reals. Observe that the numbers of given fixed modulus just form a circle centered around the origin in the complex plane. Now, consider any complex number z 0 = (a 0 + b 0 i) C. If we repeatedly square this number, z i zi 1 2, for i = 1, 2, 3,.... then it is easy to verify that with each step the modulus is also squared. If the modulus of z 0 is strictly smaller than 1, then the resulting sequence of complex numbers will become smaller and smaller (in terms of their moduli) and hence will converge to the origin in the limit. If the modulus of z 0 is strictly larger than 1, the moduli Lecture 11 1 Spring 2018

will grow to infinity, implying that the sequence will move arbitrarily far from the origin. inally, if the modulus is equal to 1, it will remain so, and the sequence will spiral around the unit circle. In general, we can do this using any function f : C C on the complex plane. We define the attractor set (or fixed-point set) to be a subset of nonzero points that remain fixed under the mapping. Note that it is the set as a whole that is fixed, even though the individual points tend to move around (see ig. 1). ig. 1: An iterated function. The subset within the blue region converges to the origin. The attractor set (the black curved boundary) is preserved under the function. Julia and Mandelbrot Sets: or any complex constant c C, consider the iterated function z i z 2 i 1 + c for i = 1, 2, 3,... Now as before, under this function, some points will tend toward and others towards finite numbers. However there will be a set of points that will tend toward neither. Altogether these latter points form the attractor of the function system. This is called the Julia set for the point c. An example of such a set is shown in ig. 2(a). (a) (b) ig. 2: (a) a Julia set and (b) the Mandelbrot set. Lecture 11 2 Spring 2018

A common method for approximately rendering Julia sets is to iterate the function until the modulus of the number exceeds some prespecified threshold. If the number diverges, then we display one color, and otherwise we display another color. How many iterations? It really depends on the desired precision. Points that are far from the boundary of the attractor will diverge quickly. Points that very close, but just outside the boundary may take much longer to diverge. Consequently, the longer you iterate, the more accurate your image will be. or some complex numbers c the associated Julia set forms a connected set of points in the complex plane. or others it is not. or each point c in the complex plane, if we color it black if Julia(c) is connected, and color it white otherwise, we will a picture like the one shown below. This set is called the Mandelbrot set (see ig. 2(b)). ractal Dimension: One of the important elements that characterizes fractals is the notion of fractal dimension. ractal sets behave strangely in the sense that they do not seem to be 1-, 2-, or 3-dimensional sets, but seem to have noninteger dimensionality. What do we mean by the dimension of a set of points in space? Intuitively, we know that a point is zero-dimensional, a line (or generally a curve) is one-dimensional, and plane (or generally a surface) is two-dimensional, and so on. If you put the object into a higher dimensional space (e.g., a line in 5-space) it does not change the dimensionality of the object, it is still a 1-dimensional set. If you continuously deform an object (e.g. deform a line into a circle or a plane into a sphere) it does not change its dimensionality. How do you define the dimension of a set in general? There are various methods. Here is one, which is called fractal dimension. Suppose we have a set in d-dimensional space. Define a d-dimensional ε-ball to the interior of a d-dimensional sphere of radius ε. An ε-ball is an open set (it does not contain its boundary) but for the purposes of defining fractal dimension this will not matter much. In fact it will simplify matters (without changing the definitions below) if we think of an ε-ball to be a solid d-dimensional hypercube whose side length is 2ε (an ε-square). The dimension of an object depends intuitively on how the number of balls its takes to cover the object varies with ε. irst consider the case of a line segment. Suppose that we have covered the line segment with n ε-balls. If we decrease the size of the covering balls exactly by 1/2, it is easy to see that it takes roughly twice as many, that is, 2n, to cover the same segment (see ig. 3(a)). n 2n n 4n (a) (b) ig. 3: The growth rate of covering numbers and fractal dimension. Next, let s consider a square that has been covered with n ε-balls. If we decrease the radius by 1/2, we see that its now takes roughly four times, that is, 4n, as many balls (see ig. 3(b)). Lecture 11 3 Spring 2018

Similarly, one can see that with a 3-dimensional cube, reducing the radius by a factor of 1/2 increasing the number of balls needed to cover by a factor of 2 3 = 8. While this is easiest to see for cubes, it generally holds (in the limit) for any compact solid object. This suggests that the nature of a d-dimensional object is that the number of balls of radius ε that are needed to cover this object grows as (1/ε) d. To make this formal, given an object X in d-dimensional space, define N(X, ε) = smallest number of ε-balls needed to cover X. (It will not be necessary to the absolute minimum number, as long as we do not use more than a constant factor times the minimum number.) We claim that an object X has dimension d if N(X, ε) grows as c(1/ε) d, for some constant c. This applies in the limit, as ε tends to 0. How do we extract this value of d? Observe that if we compute ln N(X, ε) (any base logarithm will work) we get ln c + d ln(1/ε). As ε tends to zero, the constant term c remains the same, and the d ln(1/ε) becomes dominant. If we divide this expression by ln(1/ε) we will extract the d. Thus we define the fractal dimension of a set X to be ormally, a set is said to be a fractal if: (i) it is self-similar (at different scales) (ii) it has a noninteger fractal dimension ln N(X, ε) d = lim. ε 0 ln(1/ε) The Sierpinski Triangle: Let s try to apply this to a more interesting object. Consider the triangular set X 0 shown in the upper right of ig. 4. To form X 1, we scale X 0 by 1/2, and place three copies of it within the outline of the original set. To form X 2, we scale X 1 by 1/2, and place three copies of it as before. Let X = lim i X i. This limit is called the Sierpinski triangle. X 0 X 1 X 2 X 3 X 1 3 9 = 3 2 27 = 3 3 ig. 4: The Sierpinski triangle. Lecture 11 4 Spring 2018

In order to compute the fractal dimension of X, let s see how many ε-balls does it take to cover this figure. It takes one 1-ball to cover X 0, three (1/2)-balls to cover X 1, nine (1/4)-balls to cover X 2, and in general 3 k, (1/2 k )-balls to cover X k. Letting ε = 1/2 k, it follows that N(X k, 1/2 k ) = 3 k. Thus, the fractal dimension of the Sierpinski triangle is d = lim ε 0 ln N(X, ε) ln(1/ε) ln N(X k, (1/2 k )) = lim k ln(1/(1/2 k )) ln 3 k = lim k ln 2 k = lim k ln 3 k k ln 2 = lim ln 3 k ln 2 = ln 3 ln 2 1.58496.... Thus although the Sierpinski triangle resides (or has been embedded) in 2-dimensional space, it is essentially a 1.58... dimensional object, with respect to fractal dimension. Although the above derivation is general, it is often easier to apply the following formula for fractals made through repeated subdivision. Suppose we form an object by repeatedly replacing each piece of size x by b nonoverlapping pieces each of size x/a each. Then the fractal dimension will be d = ln b ln a. The Koch Island: As another example, consider the limit of the shapes K 0, K 1,... shown in ig. 4. We start with a square, and with each iteration we replace each line segment of length x by a chain of 8 subsegments each of length x/4. The limiting shape is called the Koch Island. Note that the area does not change with each iteration, since for each outward bump there is a matching inward bump. However, the perimeter doubles with each iteration, and hence tends to infinity in the limit. The object itself is of fractal dimension 2, but the object s boundary has fractal dimension ln 8 ln 4 = 1.5. Since this is not an integer, the boundary of the Koch Island is a fractal. K 0 K 1 K 2 K 3... ig. 5: The Koch Island. L-Systems: Next, we will consider a related issue of how to generate tree-like objects, which are characterized by a process of growth and branching. The standard approach is through a structure called an L-system. L-systems, short for Lindenmayer-systems, were first proposed by a biologist Aristid Lindenmayer in 1968, as a mechanism for defining plant development. Lecture 11 5 Spring 2018

ig. 6: Examples of simple plant models generated by L-systems. If you have taken a course in formal language theory, the concept of an L-system is very similar to the concept of a context-free grammar. We start with an alphabet, V which is a finite set of characters, called symbols or variables. There is one special symbol (or generally a string) ω V, called the start symbol (or start string). inally, there is a finite set of production rules. Each production replaces a single variable with a string (or zero or more) symbols (which may be variables or constants). Such a rule is expressed in the following form: variable string. Letting V denote the variables, ω denote the start symbol/string, and P denote the production rules, an L-system is formally defined by the triple (V, ω, P ). Symbols are categorized in two types: variables are symbols that appear on the left-hand sides of production rules and can be replaced, and constants (or terminals), which cannot be replaced. An L-system is said to be deterministic if for each variable, there is a single rule having this variable on its left side. To get a better grasp on this, let us consider a simple example, developed by Lindenmayer himself to describe the growth of the Anabaena catenula algae (see ig. 7(a)). The variables are V = {A, B}, there are no constants, the start symbol is ω = A, and the rules are: P = {A AB; B A} An L-system works as follows. Starting with the start symbol, we repeatedly replace each variable with a compatible rule. In this case, each occurrence of A is mapped to AB and each occurrence of B is mapped to A. This is repeated for some desired number of levels (see ig. 7(b)). As an aside, if you count the number of symbols in each of the strings, you ll observe the sequence 1, 2, 3, 5, 8, 13, 21,.... Is this sequence familiar? This is the famous ibonacci sequence, which has been observed to arise in the growth patterns of many organisms. Using L-Systems to Generate Shapes: So what does this have to do with shape generation? The idea is to let each symbol represent some sort of drawing command (e.g., draw a line segment, turn at a specified angle, etc.) This is sometimes referred to as turtle geometry (I Lecture 11 6 Spring 2018

A AB ABA ABAAB ABAABABA (a) (b) ig. 7: L-system modeling the growth of the Anabaena catenula algae. guess this is because each command is thought of as being relayed to a turtle who carries out the drawing process). The system is defined by two parameters, a step size d and a angle increment δ. The state of the turtle is defined by a triple (x, y, α), where (x, y) is the turtle s current position and α is its heading, the direction it is currently facing. Define the following commands (see ig. 8(a)): : Move forward by a step of length d in the current direction, that is, change the state from (x, y, α) to the new state (x + d cos α, y + d sin α, α), and draw a line from the current position to the new position. f : Same as, but just move without drawing a line. + : Increase the turn angle by δ, that is, change the state from (x, y, α) to (x, y, α + δ). : Decrease the turn angle by δ, that is, change the state from (x, y, α) to (x, y, α δ). δ δ + (x, y) α f + Current α + δ + α δ + start (a) (b) start + + (c) + ig. 8: Turtle-geometry operations. As an example, let us consider how to design a turtle-geometry L-system that generates the Koch Island given earlier. Let d = 1 and δ = 90. Let us assume that we start in the lower-left corner of the square ((x, y) = (0, 0)) and the heading is to the east (α = 0). V = {, f, +, } ω = + + + p = { + + + } Lecture 11 7 Spring 2018

Observe that ω generates a unit square (four line segments with 90 turns between each, see ig. 8(b)). Then with each subsequent level we replace each existing line segment () with 8 segments, with appropriate turns in between (see ig. 8(c)). To match the scale of earlier example, we can adjust d i = 1/4 i in order to generate K i. This reflects the fact that with each iteration, the lengths of the line segments decreases by a factor of 1/4. Turtle-Based Trees: Let us extend this to the generation of tree-like objects. To make this possible, we will introduce two special symbols [ and ] which intuitively mean respectively to save the current state on a push-down stack and to pop the stack and restore this as the current state. Such a system is called an L-system with brackets. Let s see if we can apply this for generating a turtle-geometry drawing of a simple tree-like structure shown in ig. 9. Intuitively, we identify the symbol 0 with a small stem and a circular leaf. This will be our starting tree, that is ω = 0. 0 1[+0][ 0] + 0 0 1[+1[+0][ 0]][ 1[+0][ 0]] 1[+1[...left...][ 1[...right...]] 0 0 0 0 0 0 0 1 1 0 0 0 1 1 1 1 0 1 1 0 0 1 start start start start n = 0 n = 1 n = 2 n = 3 ig. 9: A simple tree-like structure generated by an L-system with brackets. (Note that the figure is not drawn exactly to scale.) With each branching, the scale factor decreases by roughly 1/2. To grow the tree, we will generate a stem, which will be modeled by a line segment of unit length in the current direction, and will be denoted in our system by the symbol 1. The first-level tree consists of a stem with two copies of the leaf unit, each of half the original size, one rotated by 45 and the other rotated by 45. To obtain this, we define two state-control symbols, +, which scales by roughly 1/2 and rotates CCW by 45 and, which scales by roughly 1/2 and rotates CW by 45. Thus, our first-level tree can be described by the string 1[ + 0] [ 0]. The next level arises by replacing each of the leaf structures in the same recursive manner. This suggests the following L-system: V = {0, 1, +,, [, ]} ω = 0 P = {0 1[ + 0] [ 0]} If we carry out the first few stages of the expansion, we have the following sequences. The 1 1 Lecture 11 8 Spring 2018

associated sequence of drawings is shown in ig. 9. n = 0 : 0 n = 1 : 1[ + 0] [ 0] n = 2 : 1[ + 1[ + 0] [ 0]] [ 1[ + 0] [ 0]] n = 3 : 1[ + 1[ + 1[ + 0] [ 0]] [ 1[ + 0] [ 0]]] [ 1[ + 1[ + 0] [ 0]] [ 1[ + 0] [ 0]]] Randomization and Stochastic L-Systems: As described, L-systems generate objects that are too regular to model natural objects. However, it is an easy matter to add randomization to the process. The first way of introducing randomness is to randomize the graphical/geometric operations. or example, rather than mapping terminal symbols into fixed actions (e.g., draw a unitlength line segment), we could add some variation (e.g., draw a line segment whose length is a random value between 0.9 and 1.1). Examples include variations in drawing lengths, variations in branching angles, and variations in thickness and/or texture (see ig. 6). While the above modifications alter the geometric properties of the generated objects, the underlying structure is still the same. We can modify L-systems to generate random structures by associating each production rule with a probability, and apply the rules randomly according to these probabilities. or example consider the following two rules: a [0.4] a[b] a [0.6] b[a]b The interpretation is that the first rule is to by applied 40% of the time and the second rule 60% of the time. Lecture 11 9 Spring 2018