Recursive Turtle Programs and Conformal Iterated Function Systems for Fractal Generation, Study notes of Computer Graphics

The connection between recursive turtle programs and conformal iterated function systems in generating fractals. The text establishes the equivalence of these two methods and shows that the fractals generated by recursive turtle programs are independent of the base case. The document also includes two lemmas that help prove the equivalence and provides examples of sierpinski gasket generation using both methods.

Typology: Study notes

Pre 2010

Uploaded on 08/18/2009

koofers-user-fk7-1
koofers-user-fk7-1 🇺🇸

10 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture 8: Recursive Turtle Programs and Conformal Iterated Function Systems
convert, and be healed. Isaiah 6:10
1. Motivating Questions
We have studied two methods for generating fractals: recursive turtle programs and iterated
function systems. We have also examined many fractal curves that can be generated by both
methods. Whenever there are two seemingly dissimilar approaches to accomplishing the same task,
questions naturally arise concerning how the two techniques are related. For fractals we ask:
1. Is it always true that a fractal generated by one method can be generated by the other technique?
2. Do there exist algorithms that convert recursive turtle programs into iterated functions systems?
3. Do there exist algorithms that convert iterated function systems into recursive turtle programs?
The turtle commands FORWARD, MOVE, TURN, and RESIZE embody the conformal
transformations TRANSLATE, ROTATE, and SCALE. Since there exist affine transformations
such as non-uniform scaling which are not conformal, there exist fractals that can be generated by
iterated function systems that cannot be generated by recursive turtle programs. But as long as we
restrict our attention to iterated function systems consisting solely of conformal transformations,
then the answer to all three questions is yes.
The purpose of this lecture is to establish these results by investigating the connections between
recursive turtle programs and conformal iterated function systems. Using the equivalence of
recursive turtle programs and conformal iterated function systems, we shall also establish that the
fractals generated by recursive turtle programs are independent of the base case.
2. The Effect of Changing the Turtle’s Initial State
A (non-recursive) turtle program is simply a finite sequence of FORWARD, MOVE, TURN,
and RESIZE commands. In this section we are going to study the effect of changing the turtle’s
initial state on the geometry generated by a turtle program. The insights we shall develop here are
actually the keys to understanding the relationship between recursive turtle programs and conformal
iterated function systems.
The turtle knows only her state
(P,v),
where P is her position and v her direction vector.
Besides sometimes drawing a line, all that the turtle commands really do is change the state of the
turtle. Now consider two possible turtle states:
S1=(P
1,v1)
and
S2=(P2,v2)
. Is it always
possible for the turtle to get from one state to the other? Sure. In fact, we can see from Figure 1
that there is always a sequence of four turtle commands --
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Recursive Turtle Programs and Conformal Iterated Function Systems for Fractal Generation and more Study notes Computer Graphics in PDF only on Docsity!

Lecture 8: Recursive Turtle Programs and Conformal Iterated Function Systems

convert, and be healed. Isaiah 6:

1. Motivating Questions

We have studied two methods for generating fractals: recursive turtle programs and iterated

function systems. We have also examined many fractal curves that can be generated by both

methods. Whenever there are two seemingly dissimilar approaches to accomplishing the same task,

questions naturally arise concerning how the two techniques are related. For fractals we ask:

  1. Is it always true that a fractal generated by one method can be generated by the other technique?
  2. Do there exist algorithms that convert recursive turtle programs into iterated functions systems?
  3. Do there exist algorithms that convert iterated function systems into recursive turtle programs?

The turtle commands FORWARD, MOVE, TURN, and RESIZE embody the conformal

transformations TRANSLATE, ROTATE, and SCALE. Since there exist affine transformations

such as non-uniform scaling which are not conformal, there exist fractals that can be generated by

iterated function systems that cannot be generated by recursive turtle programs. But as long as we

restrict our attention to iterated function systems consisting solely of conformal transformations,

then the answer to all three questions is yes.

The purpose of this lecture is to establish these results by investigating the connections between

recursive turtle programs and conformal iterated function systems. Using the equivalence of

recursive turtle programs and conformal iterated function systems, we shall also establish that the

fractals generated by recursive turtle programs are independent of the base case.

2. The Effect of Changing the Turtle’s Initial State

A (non-recursive) turtle program is simply a finite sequence of FORWARD, MOVE, TURN,

and RESIZE commands. In this section we are going to study the effect of changing the turtle’s

initial state on the geometry generated by a turtle program. The insights we shall develop here are

actually the keys to understanding the relationship between recursive turtle programs and conformal

iterated function systems.

The turtle knows only her state

( P , v ), where P is her position and v her direction vector.

Besides sometimes drawing a line, all that the turtle commands really do is change the state of the

turtle. Now consider two possible turtle states:

S

1

= ( P

1 , v 1 ) and

S

2

= ( P

2 , v 2 ). Is it always

possible for the turtle to get from one state to the other? Sure. In fact, we can see from Figure 1

that there is always a sequence of four turtle commands --

TURN(A), MOVE(D), TURN(

− B ), RESIZE(R)

-- that maps the turtle from

S

1 to

S

2

. Similarly, there is a sequence of three conformal

transformations consisting of translation, rotation, and uniform scaling that maps

S

1 to

S

2

P 1

v 1

P 2

v 2

D

A

B

A − B

Figure 1: A pair of turtle states:

S

1

= ( P

1 , v 1 ) and

S

2

= ( P

2 , v 2 ). The turtle can get from

S

1 to

S

2 by executing the commands: TURN(A), MOVE(D), TURN(

B ), RESIZE(R), where

R = length ( v 2 ) / length ( v 1 ). Similarly, executing consecutively the three conformal transformations

TRANS ( P

2

− P

1

ROT ( P

2

, A − B ) ,

SCALE ( P

2 , R ) maps

S

1 to

S

2

Now we are going to make two key observations that will help guide us to an understanding of

the relationships between recursive turtle programs and conformal iterated function systems.

Lemma 1: Suppose that

S

1

, S

2 = two turtle states

T

1

, T

2 = two turtle programs that differ only by their initial states

S

1

, S

2

G

1

, G

2 = geometry generated by

T

1

, T

2

M = conformal transformation that maps

S

1 to

S

2

Then

G

2

= M ( G

1

Proof: Clearly if we change the turtle’s initial state by, for example, a TURN( A ) command, the

turtle will still draw exactly the same shape, but rotated by A radians. Similarly, MOVE( D ) will

translate the shape and RESIZE( R ) will scale the shape. But we have just seen that we can get from

any turtle state to any other turtle state by a sequence of four such turtle commands. Thus if M is

the affine transformation corresponding to these four turtle commands and

G

1

, G

2 are the geometry

generated by the turtle programs

T

1

, T

2 , then

G

2

= M ( G

1

The effects of the turtle programs SHIFT, SPIN, and SCALE are examples of Lemma 1 in

action.

Let

M

k be the conformal transformation that maps

S

0 to

S

k -- that is,

M

k

: S

0

→ S

k

Define a conformal iterated function system by setting

CIFS = { M

1

,K, M

p

Condensation Set =

G

R

We shall show that starting with the same base case, level for level the RTP and this CIFS generate

exactly the same geometry.

Let

G

B be the geometry drawn in base case -- that is, the geometry drawn by

T

B -- and let

L

n be

the geometry drawn by the nth level of the recursive turtle program. The key insight is that at the

( n + 1 )

st level, every recursive call draws the geometry

L

n , but starting from a different initial state.

Thus by Lemma 2

L

0

= G

B

L

n + 1

= M

1

( L

n

)∪L∪ M

p

( L

n

) ∪ G

R

On the other hand, let

F

n be the geometry drawn by the nth iteration of the iterated function system.

If we start the iteration with the base case

G

B , then by the definition of an IFS with a condensation

set,

F

0

= G

B

F

n + 1

= M

1

( F

n

)∪L∪ M

p

( F

n

) ∪ G

R

Therefore, by induction, level for level the recursive turtle program and the conformal iterated

function system generate exactly the same geometry.

Corollary 1: Every fractal generated by a recursive turtle program can be generated by an

iterated function system consisting solely of conformal transformations. Moreover, the number of

conformal transformations in the CIFS is equal to the number of recursive calls in the RTP.

Proof: This result is an immediate consequence of the statement and proof of Theorem 1.

Corollary 2: The fractal drawn by a recursive turtle program is independent of the geometry

drawn in the base case.

Proof: This result follows from Theorem 1 because by the Fractal Theorem in Lecture 7, the fractal

generated by an IFS is independent of the geometry in the base case.

Theorem 2: For every iterated function system consisting solely of conformal transformations

(CIFS), there exists a recursive turtle program (RTP) such that starting with the same base case,

level for level the CIFS and the RTP generate exactly the same geometry.

Proof: Given a conformal iterated function system

CIFS = { M

1

,K, M

p

Condensation Set =

G

R

we seek a recursive turtle program that generates, level for level, the same curves as this IFS. Fix an

initial turtle state

S

0 , and let

S

k be the turtle state into which

S

0 is mapped by the conformal

transformation

M

k

. From our observations in Section 2, we know that for every k there is a

sequence of turtle commands

T

k consisting of MOVE, TURN, and RESIZE commands that map

S

k − 1 to

S

k

. We will use these turtle commands to transition between recursive calls. To finish the

recursive turtle program, let

T

p + 1 be the turtle commands that draw the condensation set

G

R and

return the turtle to her initial state. For the base case of the recursive turtle program, we can choose

any turtle program

T

B that draws some geometry

G

B and returns the turtle to her initial state

S

0

We claim that the following recursive turtle program generates, level for level, the same geometry as

the given CIFS:

  • Base Case: Turtle Program (

T

B

  • Recursion:

Turtle Commands ( T 1 ), Turtle Recursion

M

Turtle Commands ( T p ), Turtle Recursion

Turtle Commands ( T p + 1

Let

L

n be the geometry drawn by the nth level of this recursive turtle program. Again the key

insight is that at the

( n + 1 )

st level, the kth recursive call draws the geometry

L

n , but starting from

the initial state

S

k

. Since

M

k

: S

0

→ S

k , it follows by Lemma 2 that

L

0

= G

B

L

n + 1

= M

1

( L

n

)∪L∪ M

p

( L

n

) ∪ G

R

On the other hand, let

F

n be the geometry drawn by the nth iteration of the conformal iterated

function system. If we start the iteration with the base case

G

B , then by the definition of an IFS,

F

0

= G

B

F

n + 1

= M

1

( F

n

)∪L∪ M

p

( F

n

) ∪ G

R

Therefore, by induction, level for level, the recursive turtle program and the conformal iterated

function system generate exactly the same geometry.

  1. Finding the CIFS

a.

N

k = product of the transformations between the

( k − 1 )

st and

k

th recursive call.

b.

M

1

= N

1 = product of the transformations before the first recursive call.

c.

M

k

= M

k − 1

∗ N

k

d.

CIFS = { M

1

,K M

p } { p = number of recursive calls}

Example 1: Sierpinski Gasket -- Ron’s Method

Outer Triangle

Vertices =

( P

1

, P

2

, P

3

Edges =

( w 1 , w 2 , w 3

Recursive Turtle Program Transformations

BASE CASE: TRIANGLE

RECURSION:

REPEAT 3 TIMES

RESIZE 1/

SCALE P

k ( ,^1 /^2 )

RECUR

RESIZE 2

SCALE P

k ( ,^2 )

MOVE 1

TRANS ( w k

TURN

2 π / 3

ROT P

k + 1 ( ,^2 π^ /^3 )

Conformal Iterated Function System

M

1

= SCALE P

1 ( ,^1 /^2 )

M

2

= M

1

∗ SCALE ( P

1 , 2)∗ TRANS ( w 1

) ∗ ROT P

2 ( ,^2 π^ /^3 ) ∗^ SCALE^ P 2 ( ,^1 /^2 )

= TRANS ( w 1

) ∗ ROT P

2 ( ,^2 π^ /^3 )∗^ SCALE^ P 2 ( ,^1 /^2 )

M

3

= M

2

∗ SCALE ( P

2 , 2 ) ∗ TRANS ( w 2

) ∗ ROT P

3 ( ,^2 π^ /^3 )∗^ SCALE^ P 3 ( ,^1 /^2 )

= TRANS ( w 1

) ∗ ROT P

2 ( ,^2 π^ /^3 )∗^ TRANS ( w 2

) ∗ ROT P

3 ( ,^2 π^ /^3 ) ∗^ SCALE^ P 3 ( ,^1 /^2 )

Notice that in Ron’s algorithm, the transformations depend on the turtle’s current state. Thus

Ron’s algorithm has the annoying property that it must keep track of the turtle’s state after each

turtle command. For the Sierpinski gasket, keeping track of the turtle’s state is easy, but for many

other fractals it is not so straightforward to keep track of the turtle’s state.

Tao’s algorithm takes a turtle-centric point of view, a perspective from inside the turtle’s

domain. From the turtle’s viewpoint, the turtle is always at the center of the universe (the origin)

facing in the direction of the x -axis ( ivec ), so there is no need to keep track of the turtle’s state.

Therefore, viewed from inside the turtle, the turtle commands correspond to the following conformal

transformations:

FORWARD DTRANS (^) ( ivecSCALE ( D ))

MOVE DTRANS (^) ( ivecSCALE ( D ))

TURN AROT ( Origin , A ) = ROT ( A )

RESIZE sSCALE ( Origin , s ) = SCALE ( s ).

There is one novel detail here. When we apply transformation matrices to compute the new

coordinates of a point or vector, we multiply on the right:

Q

new

= Q

oldM. But when we apply

these transformations to change the state of the turtle -- the turtle’s local coordinate system -- then

we must multiply on the left. For suppose that the turtle is in the state

S = ( P , v ). Then

FORWARD D

MOVE D

v new = v

v new

⊥ = v

P

new = P + D v

v new

v new

P

new

D 0 1

v

v

P

RESIZE s

v new = s v

v new

⊥ = s v

P

new

= P

v new

v new

P

new

s 0 0

0 s 0

v

v

P

TURN A

v new = cos( A ) v + sin( A ) v

v new

⊥ = − sin( A ) v + cos( A ) v

P

new

= P

v new

v new

P

new

cos( A ) sin( A ) 0

−sin( A ) cos( A ) 0

v

v

P

These observations lead to the following result.

Proposition: If

L

1

,K, L

n are the transformation matrices corresponding to the turtle commands

C

1

,K, C

n , then

L = L

n

∗L∗ L

1 is the transformation matrix corresponding to the turtle program

C

1

,K, C

n

Proof: Let

S

k denote the state of the turtle after executing the command

C

k

. Since

L

k

∗ S

k − 1

= S

k

it follows that

L ∗ S

0

= ( L

n

∗L∗ L

1

)∗ S

0

= S

n

5. Bump Fractals

The easiest way to describe a bump is with a turtle program. When we studied bump fractals,

we observed that we could generate the recursive turtle program for a bump fractal directly from the

turtle program for the bump. We would like to do the same for iterated function systems: that is,

we would like to extract the IFS for the bump fractal directly from a simple turtle description of the

bump. Since we know how to get from a turtle description of a bump to a recursive turtle program

for the bump fractal and since we know how to convert from a recursive turtle program to an

iterated function system, all we need to do to get from a turtle description of a bump to an iterated

function system for the bump fractal is to combine these two procedures. We exhibit this algorithm

in Table 1. In order to avoid keeping track of the turtle’s state, we use Tao’s algorithm to convert

from a recursive turtle program to an iterated function system.

Bump Fractal ( Level ) CIFS

Base Case: FORWARD 1

Recursion:

TURN

A

1

→ TURN

A

1

ROT A

( 1 )

RESIZE

S

1

→ RESIZE

S

1

SCALE S

( 1 )

FORWARD 1 → Fractal

( Level − 1 ) →

TRANS ( ivec )

TURN

A

2

→ TURN

A

2

ROT A

( 2 )

RESIZE

S

2

→ RESIZE

S

2

SCALE S

( 2 )

FORWARD 1 → Fractal

( Level − 1 ) →

TRANS ( ivec )

M M

TURN

A

n

→ TURN

A

n

ROT A

( (^) n )

RESIZE

S

n

→ RESIZE

S

n

SCALE S

( (^) n )

FORWARD 1 → Fractal

( Level − 1 )

TURN

A

n + 1

→ TURN

A

n + 1

RESIZE

S

n + 1

→ RESIZE

S

n + 1

Table 1: Bump

→ Recursive Turtle Program

→ CIFS. All the rotation and scaling commands

are around the origin. The last three bump commands -- FORWARD 1, TURN

A

n + 1 , and RESIZE

S

n + 1 -- are ignored by the iterated function system, since the only purpose of these commands in

the bump program is to conduct the turtle to her final state. To read off the IFS from the

transformations in the last column, simply write down the transformations in reverse order and

group them between successive appearances of

Trans ( ivec ) (see Example 3).

Example 3: Koch Curve

Koch IFS Koch Bump Koch ( Level )

Base Case: FORWARD 1

Recursion:

SCALE (^) ( 1 / (^3) )

← RESIZE 1/

→ RESIZE 1/

TRANS ( ivec )

← FORWARD 1

→ Koch ( Level-1)

ROT ( π / (^3) )

← TURN

π / 3

→ TURN

π / 3

TRANS ( ivec )

← FORWARD 1

→ Koch ( Level-1)

ROT (^) (− 2 π / (^3) )

← TURN

− 2 π / 3

→ TURN

− 2 π / 3

TRANS ( ivec )

← FORWARD 1

→ Koch ( Level-1)

ROT ( π / (^3) )

← TURN

π / 3

→ TURN

π / 3

FORWARD 1

→ Koch ( Level-1)

RESIZE 3

→ RESIZE 3

Rot ( π / 3 ) ∗ Trans ( ivec )∗ Rot (− 2 π / 3 ) ∗ Trans ( ivec )∗ Rot ( π / 3 ) ∗ Trans ( ivec )∗ Scale (^) ( 1 / (^3) )

M 1

M (^) 2

M 3

M (^) 4

A CIFS for the Koch curve is given by the transformations

{ M

1

, M

2

, M

3

, M

4 }. To find these

transformations, we list in column 1 the transformations corresponding to the turtle program in

column 2 for the Koch bump. We then write these transformations horizontally in reverse order

and group these products between successive appearance of

Trans ( ivec ).

6. Summary

The main result of this lecture is the equivalence between recursive turtle programs (RTP) and

conformal iterated function systems (CIFS). The conformal transformations in the CIFS

correspond to changes of state between successive recursive calls in the RTP; the condensation set

of the CIFS is the geometry drawn during highest level of the recursive phase of the RTP. These

and other explicit correspondences between recursive turtle programs and conformal iterated

functions systems are summarized in Table 2. Since, by the trivial fixed point theorem, the fractal

generated by an iterated function system is independent of the base case, it follows from our

equivalence theorems that the fractal generated by a recursive turtle program is also independent of

the base case.

  1. Consider the bumps in Lecture 2, Figure 9.

a. Write a turtle program to generate each of these bumps.

b. Write a recursive turtle program to generate the bump fractals corresponding to each of

these bumps.

c. Describe the transformations in the conformal iterated function systems that generate each

of these bump fractals.

  1. Consider the bumps in Lecture 2, Figure 13.

a. Write a turtle program to generate each of these bumps.

b. Write a recursive turtle program to generate the bump fractals corresponding to each of

these bumps.

c. Describe the transformations in the conformal iterated function systems that generate each

of these bump fractals.

  1. Consider the bumps in Lecture 2, Figure 14.

a. Write a turtle program to generate each of these bumps.

b. Write a recursive turtle program to generate the bump fractals corresponding to each of

these bumps.

c. Describe the transformations in the conformal iterated function systems that generate each

of these bump fractals.

  1. Consider the bumps in Lecture 2, Figure 15.

a. Write a turtle program to generate each of these bumps.

b. Write a recursive turtle program to generate the bump fractals corresponding to each of

these bumps.

c. Describe the transformations in the conformal iterated function systems that generate each

of these bump fractals.

  1. Consider the iterated function systems for the Sierpinski gasket generated from the standard

recursive turtle program for the Sierpinski gasket by Ron’s Algorithm (Example 1) and by Tao’s

Algorithm (Example 2).

a. Show that these two iterated function systems are identical.

b. Show that these two iterated function systems are not identical to the standard iterated

function system for the Sierpinski gasket given by the three scaling transformations

Scale ( P 1

Scale ( P 2

Scale ( P 3

c. Conclude from part b that the IFS for generating a fractal is not unique.

d. Construct a recursive turtle program that corresponds to the standard iterated function

system for the Sierpinski gasket given in part b.

  1. Prove that the classical turtle and the hodograph turtle (see Lecture 2, Project 2) generate the

same fractal when both of the following conditions are satisfied:

i. the pen is down and the anchor is up during the base case;

ii. both the pen and the anchor are up during the recursive body of the program.

  1. Consider the left-handed turtle described in Lecture 2, Project 4.

a. Show that if we replace the classical turtle by the left-handed turtle and conformal

transformations by arbitrary affine transformations, then

i. Lemma 1 and Lemma 2 remain valid.

ii. Theorems 1, 2 and Corollaries 1-4 remain valid.

b. Explain how to extend Tao’s algorithm to convert recursive turtle programs for the left-

handed turtle to iterated functions systems consisting of arbitrary affine transformations.

  1. Using an iterated function system with affine transformations:

a. Build a fractal that cannot be generated by a recursive turtle program for the classical turtle.

b. Construct a recursive turtle program for the left-handed turtle that generates the fractal in

part a.

Programming Projects:

  1. Parsers

a. Write a parser to convert recursive programs for the classical turtle into conformal iterated

function systems that generate the same fractal.

b. Write a parser to convert recursive turtle programs for the left-handed turtle into iterated

function systems that generate the same fractal (see Exercise 10).

  1. Open Problem s (See Exercise 8)

a. Develop an algorithm that given two arbitrary iterated function systems determines whether

the two systems generate the same fractal or show that no such algorithm exists.

b. Develop an algorithm that given two arbitrary recursive turtle programs determines whether

the two programs generate the same fractal or show that no such algorithm exists.

Note that by the results in this chapter, the preceding two open problems are equivalent.