1Fractals_02aaa - e-campus - Sri Ramanujar Engineering College

Download Report

Transcript 1Fractals_02aaa - e-campus - Sri Ramanujar Engineering College

Dr. B.Raghu
Professor / CSE
Sri Ramanujar Engineering College
Topics
 Why fractals?
 Fractal Dimension
 Mandelbrot Set
 Fractal Applications
4/4/2016
Dr. B. Raghu Professor/CSE
2
Fractals?
 Fractal geometry of nature and chaos
 The “middle ground of ‘organized’ or ‘orderly’ geometric
chaos” (Mandelbrot 1989)
 Derived partly “because of the difficulty in analyzing
spatial forms and processes” (Lam and Quattrochi
1992)
 Pack an infinite amount of length into a small finite
area, similar to the coastline scale issue (Flake 1998).
 A 1 inch Koch curve at 100 iterations would stretch around
the earth 40,000 times.
4/4/2016
Dr. B. Raghu Professor/CSE
3
Fractal Dimension
1 Dimension (line)
2=21
2 Dimensions (square)
4=22
4/4/2016
Dr. B. Raghu Professor/CSE
4
Fractal Dimension
3 Dimensions (cube)
4/4/2016
8=23
1 Dimension
2=21
2 Dimensions
4=22
3 Dimensions
8=23
d Dimensions
n=2d
Dr. B. Raghu Professor/CSE
Number of copies
made by doubling
= 2dimension
5
Fractal Dimension
Fractal Dimension
(Sierpinski Triangle)
3=2?
4/4/2016
1 Dimension
2=21
F Dimension
3=2?
2 Dimensions
4=22
3 Dimensions
8=23
d Dimensions
n=2d
Dr. B. Raghu Professor/CSE
6
Calculating Dimension with Log
 For a, the original
segment is ¼ of the line
length.
 For b, the original
square is ½ of its side.
 For c, the original curve
is 1/3 of the length of
the iterated curve.
(Lam and Quattrochi 1992)
4/4/2016
Dr. B. Raghu Professor/CSE
7
Fractal Dimension
 In fractal geometry, fractal curves are between
dimension 1 and 2, and fractal surfaces are
between dimension 2 and 3.
 Coastlines typically are about fractal dimension of 1.2,
and their relief dimension is about 2.2.

Fractal dimensions of 1.5 and 2.5 are too large, or irregular, for
modeling earth features.
 Fractal dimension is an indicator of complexity
(Zhou and Lam 2005)
 Image
Characterization and Measurement System
(ICAMS) for dimension (Ibid)
4/4/2016
Dr. B. Raghu Professor/CSE
8
The Mandelbrot Set
 Xt+1 = xt2 + c, where c = some imaginary number.
 Ex. – for c = i, x0 = 0



X1 = 0 + i
X2 = i2 + i » -1 + i
X3 = (-1 + i)2 + i » i2 – 2i + 1 + i » -i …..
 Points within the Mandelbrot
set are black.
4/4/2016
Dr. B. Raghu Professor/CSE
9
Fractal Applications
 Categorization of phenomena using dimension
similarity.
 Simulation (coast lines, stream patterns, surfaces and
terrain, etc.)
 Simulated landscapes have been used to model habitat
destruction (Malanson 2002).
 Art
4/4/2016
Dr. B. Raghu Professor/CSE
10
4/4/2016
Dr. B. Raghu Professor/CSE
Fractal Art
11
Fractals and Hollywood
 Star Trek – Genesis
Effect
 Star Wars – Death Star
 The Last Starfighter –
Landscapes
 The Perfect Storm
 Apollo 13
 Titanic
4/4/2016
Dr. B. Raghu Professor/CSE
12
Fractal geometry
 Effective way to represent natural objects
 Represents phenomenon w/ concepts of
 fragmentation

small chunks
 Self Similarity


similar small building blocks
used repeatedly
Fractal pattern generation
 Initiator
 the basic element
 Repetitor
 way in which basic element is repeatedly applied
 Important idea is recursion
 I.e. do again
 for the definition of recursion - see recursion
Fractal patterns can be
 Deterministic
 Repetitor is same each time
 Stochastic
 some part of repetitor varies randomly
Space filling curves
 firstly - why
 need ways to refer to specific tiles (cells) in a
matrix
 one (obvious) way is by x and y coordinates
3
2
1
0
0
1
2
3
Problem w/ obvious way
 requires storage of two numbers
 cannot determine neighbors w/out computation
 alternative would permit easy spatial indexing
Alternatives to x,y
 row order
 row prime order
 Cantor diagonal order
 spiral order
 we are generally concerned
w/ “space filling curves”
Peano ordering
 Peano ordering permits use of a key to stand for 2 (or
more - if object is volume) dimensions
 Peano key is derived using bit interleaving
2
1
0
0
1
2
3
Bit interleaving
3
2
X
1
0
0
00
X 0
1
2
3
01
10
11
1
1 (3)
0
0
0
Y
0
0
0
0 1
1 1
0 (2)
1
0
Topology
 relationships in space based on relative positions
 absolute position
 Thing A is at x=4, y=5 and thing B is at x=3, y=7
 relative position
 thing A is near thing B
 removal of descriptive geometry
Graphs
 not x/y graphs
 but topological graphs
 they reflect relationships
 elements
 intersections or endpoints of lines (vertices)
 lines called edges (but sometimes arcs or chains)
 separate links or disconnected sets of lines called
subgraphs
 vacant spaces (faces) between or outside edges
Isomorphic graphs
 two graphs are isomorphic if there is a one-to-one
correspondence between edges and vertices
 shapes can be quite different
Graph types
 loop, circuit or cyclic graphs
 one vertex connected to itself without the need for
traversing one edge in both directions

highway systems, electrical systems
 tree graph
 graphs without loops or cycles
 rivers
 directed acyclic graph
 no circuit but have directed edge(s)
 directed edge is simply an edge with direction associated
 sewer lines
Some special tree types
 spanning tree
 each vertex must be connected to at least one other
vertex
 traveling salesman
 must be able to return to starting point w/out retracing
an edge
 radial trees
 all peripheral vertices connect to central vertex
Properties of graphs
 degree of a vertex
 number of edges that connect
 for directed graphs number of in and out edges
 these numbers can be used to assess the overall
character of a network
 minimum/max degree, average degree etc.
 can use these measures to compute Euler number
Euler number
V+F=E+S
 where
 V is total number of vertices
 E is total number of edges
 F is number of faces
 S (or G) is Euler number
 if area outside graph is a face S = 2 otherwise 1
Computation of Euler numbers
S= 1 if “outside” is not counted as a face and S=2 if
“outside” is counted as a face
V=4, E=4, F=2, S=2
V=6, E=5, F=2, S=1
V=4, F=2, E=5, S=1
V=9, F=3 E=11, S=1
• FRACTAL LANDSCAPES
• FRACTAL IMAGE COMPRESSION
Dr. B.Raghu
Professor / CSE
Sri Ramanujar Engineering College
Review:
Two important properties of a fractal F
• F has detail at every level.
• F is exactly, approximately or statistically self-similar.
Fractal Landscapes
Fractals are now used in many forms to create textured landscapes and
other intricate models. It is possible to create all sorts of realistic fractal
forgeries, images of natural scenes, such as lunar landscapes, mountain
ranges and coastlines. This is seen in many special effects within
Hollywood movies and also in television advertisements.
A fractal planet.
A fractal landscape created by Professor
Ken Musgrave (Copyright: Ken Musgrave)
Simulation process
First:
Already known
The average of the 2 neighbor
blue points plus r
The average of the 4 neighbor
red points plus r
This random value r is normally distributed
and scaled by a factor d1 related to the
original d by
1 H /2
r ~ N (0, d1 ) d1  ( ) d
2
d is the scale constant.
H is the smoothness constant.
We can now carry out exactly the same procedure on each of the four smaller
squares, continuing for as long as we like, but where we make the scaling factor at
each stage smaller and smaller; by doing this we ensure that as we look closer into
the landscape, the 'bumps' in the surface will become smaller, just as for a real
landscape. The scaling factor at stage n is dn, given by
1
d n  ( ) nH / 2 d
2
Simulation result by MATLAB
Using a 64x64 grid and
H=1.25
d=15
FRACTAL IMAGE COMPRESSION
What is Fractal Image Compression ?
The output images converge to the Sierpinski triangle. This final
image is called attractor for this photocopying machine. Any initial
image will be transformed to the attractor if we repeatedly run the
machine.
On the other words, the attractor for this machine is always the
same image without regardless of the initial image. This feature is
one of the keys to the fractal image compression.
How can we describe behavior of the machine ? Transformations of the
form as follows will help us.
 x   ai
wi    
 y   ci
bi   x   ei 
 



di   y   f i 
Such transformations are called affine transformations. Affine
transformations are able to skew, stretch, rotate, scale and translate an
input image.
M.Barnsley suggested that perhaps storing images as collections of
transformations could lead to image compression.
Iterated Function Systems ( IFS )
An iterated function system consists of a collection of contractive
affine transformations.
W (*) 
n
wi (*)
i 1
For an input set S, we can compute wi for each i, take the union of these
sets, and get a new set W(S).
Hutchinson proved that in IFS, if the wi are contractive, then W is
contractive, thus the map W will have a unique fixed point in the space of
all images. That means, whatever image we start with, we can repeatedly
apply W to it and our initial image will converge to a fixed image. Thus W
completely determine a unique image.
| W | f  limW ( n) ( fo )
x 
Self-Similarity in Images
We define the distance of two images by:
 ( f , g )  sup | f ( x, y)  g ( x, y) |
( x , y )P
where f and g are value of the level of grey of pixel, P is the space
of the image
JAVA
Original Lena image
Self-similar portions of the image
Affine transformation mentioned earlier is able to "geometrically"
transform part of the image but is not able to transform grey level of
the pixel. so we have to add a new dimension into affine transformation
 x   ai
wi  y    ci
 z   0
bi
di
0
0   x   ei 
0   y    fi 
si   z   oi 
Here si represents the contrast, oi the brightness of the
transformation
For encoding of the image, we divide it into:
• non-overlapped pieces (so called ranges, R)
• overlapped pieces (so called domains, D)
Encoding Images
Suppose we have an image f that we want to encode. On the other words,
we want to find a IFS W which f to be the fixed point of the map W
We seek a partition of f into N non-overlapped pieces of the image to which
we apply the transforms wi and get back f.
We should find pieces Di and maps wi, so that when we apply a wi to the
part of the image over Di , we should get something that is very close to
the any other part of the image over Ri .
Finding the pieces Ri and corresponding Di by minimizing
distances between them is the goal of the problem.
Decoding Images
The decoding step is very simple. We start with any image and
apply the stored affine transformations repeatedly till the image
no longer changes or changes very little. This is the decoded
image.
First three iterations of the decompression of the image of an
eye from an initial solid grey image
An Example
Suppose we have to encode 256x256 pixel grayscale image.
let R1~R1024 be the 8x8 pixel non-overlapping sub-squares of the
image, and let D be the collection of all overlapping 16x16 pixel subsquares of the image (general, domain is 4 times greater than
range). The collection D contains (256-16+1) * (256-16+1) =
58,081 squares. For each Ri search through all of D to find Di with
minimal distances
To find most-likely sub-squares we have to minimize distance
equation. That means we must find a good choice for Di that most
looks like the image above Ri (in any of 8 ways of orientations) and
find a good contrast si and brightness oi. For each Ri , Di pair we
can compute contrast and brightness using least squares regression.
Fractal Image Compression versus JPEG Compression
Original Lena image
(184,320 bytes)
JPEG-max. quality
(32,072)
comp. ratio: 5.75:1
FIF-max. quality
(30,368)
comp. ratio: 6.07:1
Resolution Independence
One very important feature of the Fractal Image Compression is
Resolution Independence.
When we want to decode image, the only thing we have to do is
apply these transformations on any initial image. After each iteration,
details on the decoded image are sharper and sharper. That means,
the decoded image can be decoded at any size.
So we can zone in the image on the larger sizes without having the
"pixelization" effect..
Lena's eye
original image enlarged to 4 times
Lena's eye
decoded at 4 times its encoding size
Fractals
 Infinite detail at every point
 Self similarity between parts and overall features of the
object
 Zoom into Euclidian shape
 Zoomed shape see more detail
 eventually smooths
 Zoom in on fractal
 See more detail
 Does not smooth
 Model
 Terrain, clouds water, trees, plants, feathers, fur, patterns
 General equation P1=F(P0), P2 = F(P1), P3=F(P2)…
 P3=F(F(F(P0)))
Self similar fractals
 Parts are scaled down versions of the entire object
 use same scaling on subparts
 use different scaling factors for subparts
 Statistically self-similar
 Apply random variation to subparts

Trees, shrubs, other vegetation
Fractal types
 Statistically self-affine
 random variations

Sx<>Sy<>Sz
 terrain, water, clouds
 Invariant fractal sets
 Nonlinear transformations


Self squaring fractals
 Julia-Fatou set
 Squaring function in complex space
 Mandelbrot set
 Squaring function in complex space
Self-inverse fractals
 Inversion procedures
 x=>x2+c
 x=a+bi

Complex number
 Modulus
 Sqrt(a2+b2)
 If modulus < 1
Squaring makes it go toward
0
 If modulus > 1
 Squaring falls towards
infinity
Julia-Fatou and
Mandelbrot

Julia-Fatou
 If modulus=1
 Some fall to zero
 Some fall to infinity
 Some do neither

Boundary between numbers
which fall to zero and those
which fall to infinity

Julia-Fatou Set
Foley/vanDam Computer Graphics-Principles a
Practices, 2nd edition
Julia Fatou and Mandelbrot con’d
 Shape of the Julia-Fatou set based on c
 To get Mandelbrot set – set of non-diverging points
 Correct method

Compute the Julia sets for all possible c

Color the points black when the set is connected and white when it is
not connected
 Approximate method

Foreach value of c, start with complex number 0=0+0i

Apply to x=>x2+c

Process a finite number of times (say 1000)

If after the iterations is is outside a disk defined by modulus>100,
color the points of c white, otherwise color it black.
Foley/vanDam Computer Graphics-Principles and Practices, 2nd edition
4/4/2016
Dr. B. Raghu Professor/CSE
51
Constructing a deterministic self-similar
fractal
 Initiator
 Given geometric shape
 Generator
 Pattern which replaces subparts of initiator
 Koch Curve
Initiator
generator
First iteration
Fractal
dimension
 D=fractal dimension
 Amount of variation in the structure
 Measure of roughness or fragmentation of the object
 Small d-less jagged
 Large d-more jagged
 Self similar objects
 nsd=1 (Some books write this as ns-d=1)
 s=scaling factor
 n number of subparts in subdivision
 d=ln(n)/ln(1/s)

[d=ln(n)/ln(s) however s is the number of segments versus how much
the main segment was reduced
 I.e. line divided into 3 segments. Instead of saying the line is 1/3, say
instead there are 3 sements. Notice that 1/(1/3) = 3]
 If there are different scaling factors


d
n Sk =1
K=1
Figuring out scaling factors
-d
I prefer: ns =1 :d=ln(n)/ln(s)
 Dimension is a ratio of
 Koch’s snowflake
the (new size)/(old size)
 After division have 4 segments
 Divide line into n identical
segments

n=s
 Divide lines on square into
small squares by dividing
each line into n identical
segments

n=s2 small squares
 Divide cube

Get n=s3 small cubes



n=4 (new segments)
s=3 (old segments)
Fractal Dimension

D=ln4/ln3 = 1.262
 For your reference: Book
method

n=4


s=1/3


Number of new segments
segments reduced by 1/3
d=ln4/ln(1/(1/3))
Sierpinski gasket Fractal Dimension
 Divide each side by 2
 Makes 4 triangles
 We keep 3
 Therefore n=3
 Get 3 new triangles from 1 old
triangle
 s=2 (2 new segments from one
old segment)
 Fractal dimension
 D=ln(3)/ln(2) = 1.585
Cube Fractal Dimension
 Apply fractal algorithm
 Divide each side by 3
 Now push out the middle face of each cube
Image from
Angel book
 Now push out the center of the cube
 What is the fractal dimension?
 Well we have 20 cubes, where we used to have 1
 n=20
 We have divided each side by 3
 s=3
 Fractal dimension ln(20)/ln(3) = 2.727
Language Based Models of
generating images
B
 Typical Alphabet {A,B,[,]}
 A[B]AA[B]
 Rules
 A=> AA
 B=> A[B]AA[B]
 AA[A[B]AA[B]]AAAA[A[B]AA[B]]
AA
 Starting Basis=B
 Generate words
 Represents sequence of
segments in graph
structure
 Branch with brackets
 Interesting, but I want a
tree
B
B
A
A
A
A
A
B
A
A
B
AA
A
A
B
B
A
A
Language Based Models of
generating images con’d
 Modify Alphabet
B
{A,B,[,],(,)}
 Rules
 A[B]AA(B)
 AA[A[B]AA(B)]AAAA(A[B]AA(B))
 A=> AA
AA
 B=> A[B]AA(B)
A
A
A
A
 [] = left branch () = right
branchStarting Basis=B
B
 Generate words
A
A
 Represents sequence of
segments in graph
structure
 Branch with brackets
B
B
AA
A
A
B
A
A
B
A
B
Language Based models have no
inherent geometry
 Grammar based model
requires
B
 Grammar
 Geometric interpretation
AA
 Generating an object from
A
A
A
A
the word is a separate process
 examples
 Branches on the tree drawn at
upward angles
B
 Choose to draw segments of tree
as successively smaller lengths AA


A
The more it branches, the smaller
the last branch is
Draw flowers or leaves at terminal
nodes
B
A
A
A
B
Grammar and Geometry
 Change branch size according to depth of graph
Foley/vanDam Computer Graphics-Principles and
Practices, 2nd edition
Particle Systems
 System is defined by a collection of particles that evolve
over time
 Particles have fluid-like properties
 Flowing, billowing, spattering, expanding, imploding, exploding
 Basic particle can be any shape
 Sphere, box, ellipsoid, etc
 Apply probabilistic rules to particles
 generate new particles
 Change attributes according to age





What color is particle when detected?
What shape is particle when detected?
Transparancy over time?
Particles die (disappear from system)
Movement

Deterministic or stochastic laws of motion
 Kinematically
 forces such as gravity
Particle
Systems
modeling
 Model
 Fire, fog, smoke, fireworks, trees, grass, waterfall, water spray.
 Grass
 Model clumps by setting up trajectory paths for particles
 Waterfall
 Particles fall from fixed elevation

Deflected by obstacle as splash to ground
 Eg. drop, hit rock, finish in pool
 Drop, go to bottom of pool, float back up.
Physically based modeling
 Non-rigid object
 Rope, cloth, soft rubber ball, jello
 Describe behavior in terms of external and internal forces
 Approximate the object with network of point nodes connected by
flexible connection

Example springs with spring constant k
 Homogeneous object
 All k’s equal
 Hooke’s Law
 Fs=-k x
 x=displacement, Fs = restoring force on spring
 Could also model with putty (doesn’t spring back)
 Could model with elastic material
 Minimize strain energy
k
k
k
k
“Turtle
Graphics”
 Turtle can
 F=Move forward a unit
 L=Turn left
 R=Turn right
 Stipulate turtle directions,
and angle of turns
 Equilateral triangle
 Eg. angle =120
 FRFRFR
 What if change angle to 60
degrees
 F=> FLFRRFLF
 Basis F

Koch Curve (snowflake)
 Example taken from Angel book
Using turtle
graphics for trees
 Use push and pop for side




branches []
F=> F[RF]F[LF]F
Angle =27
Note spaces ONLY for
readability
F[RF]F[LF]F [RF[RF]F[LF]F]
F[RF]F[LF]F [LF[RF]F[LF]F]
F[RF]F[LF]F
Fractals
 Fractals are geometric objects.
 Many real-world objects like ferns are shaped like
fractals.
 Fractals are formed by iterations.
 Fractals are self-similar.
 In computer graphics, we use fractal functions to
create complex objects.
Koch Fractals (Snowflakes)
1/3
1
Iteration 0
1/3
Generator
Iteration 1
Iteration 2
1/3
1/3
Iteration 3
Fractal Tree
Generator
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
Fractal Fern
Generator
Iteration 0
Iteration 1
Iteration 2
Iteration 3
Add Some Randomness
 The fractals we’ve produced so far seem to be very
regular and “artificial”.
 To create some realism and variability, simply
change the angles slightly sometimes based on a
random number generator.
 For example, you can curve some of the ferns to
one side.
 For example, you can also vary the lengths of the
branches and the branching factor.
Terrain (Random Mid-point Displacement)
 Given the heights of two end-points, generate a
height at the mid-point.
 Suppose that the two end-points are a and b.
Suppose the height is in the y direction, such that
the height at a is y(a), and the height at b is y(b).
 Then, the height at the mid-point will be:
ymid = (y(a)+y(b))/2 + r, where

r is the random offset
 This is how to generate the random offset r:
r = srg|b-a|, where


s is a user-selected “roughness” factor, and
rg is a Gaussian random variable with mean 0 and variance 1
How to generate a random number with Gaussian
(or normal) probability distribution
// given random numbers x1 and x2 with equal distribution from -1 to 1
// generate numbers y1 and y2 with normal distribution centered at 0.0
// and with standard deviation 1.0.
void Gaussian(float &y1, float &y2) {
float x1, x2, w;
do {
x1 = 2.0 * 0.001*(float)(rand()%1000) - 1.0;
x2 = 2.0 * 0.001*(float)(rand()%1000) - 1.0;
w = x1 * x1 + x2 * x2;
} while ( w >= 1.0 );
}
w = sqrt( (-2.0 * log( w ) ) / w );
y1 = x1 * w;
y2 = x2 * w;
Procedural Terrain Example
Building a more realistic terrain
 Notice that in the real world, valleys and
mountains have different shapes.
 If we have the same terrain-generation algorithm
for both mountains and valleys, it will result in
unrealistic, alien-looking landscapes.
 Therefore, use different parameters for valleys and
mountains.
 Also, can manually create ridges, cliffs, and other
geographical features, and then use fractals to
create detail roughness.
Koch fractal
// x0, y0 are the starting coordinates
// x1, y1 are the ending coordinates
// xout, yout is the outward vector
// level is how many iterations to draw this koch fractal. 0 means just draw the line
void Koch2D(float x0, float y0, float x1, float y1, float xout, float yout, int level) {
float xa, xb, xd, ya, yb, yd;
// (xa,ya) is a third of the way
// (xb,yb) is two thirds of the way
// (xd,yd) is the new point
float xmid,ymid, outmag, displacemag;
}
if (level==0) { // if level 0, just draw the line
glBegin(GL_LINES);
glVertex3f(x0,y0,0.0);
glVertex3f(x1,y1,0.0);
(x0,y0)
(xa,ya)
glEnd();
} else { // otherwise, call Koch2D for the four line-segments
xa = x0+0.3333333*(x1-x0);
ya = y0+0.3333333*(y1-y0);
xb = x0+0.6666666*(x1-x0);
60 degrees or
yb = y0+0.6666666*(y1-y0);
3.14159 / 3 radians
Koch2D(x0,y0,xa,ya,xout,yout,level-1); // draw the first third
Koch2D(xb,yb,x1,y1,xout,yout,level-1); // draw the second third
outmag = sqrt(xout*xout+yout*yout);
displacemag = tan(3.14159/3.0)*sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))/6.0;
xmid = xout*displacemag/outmag;
L/6
ymid = yout*displacemag/outmag;
xd = x0+0.5*(x1-x0)+xmid;
yd = y0+0.5*(y1-y0)+ymid;
Koch2D(xa,ya,xd,yd,xa+0.5*(xd-xa)-xb,ya+0.5*(yd-ya)-yb,level-1); // protrusion
Koch2D(xd,yd,xb,yb,xd+0.5*(xb-xd)-xa,yd+0.5*(yb-yd)-ya,level-1); // protrusion
}
(xout,yout)
(xd,yd)
(xb,yb)
(x1,y1)
L
displacemag
// radius, height, iteration
void FractalTree(float r, float h, int iter) {
Fractal Tree
GLUquadricObj *optr;
// *************** Draw the vertical cylinder ************************************
optr = gluNewQuadric();
gluQuadricDrawStyle(optr,GLU_FILL);
glPushMatrix();
glRotatef(-90.0,1.0,0.0,0.0);
gluCylinder(optr,r,r,h,10,2); // ptr, rbase, rtop, height, nLongitude, nLatitudes
glPopMatrix();
// *************** If more iterations, then recursively draw branches ********
if (iter>0) {
glPushMatrix();
glTranslatef(0.0,h,0.0); // translate upwards by h
glRotatef(30.0,1.0,0.0,0.0); // rotate about the x axis by 30 degrees
FractalTree(0.8*r,0.8*h,iter-1); // draw the next iteration fractal tree
glPopMatrix();
glPushMatrix();
glTranslatef(0.0,h,0.0); // translate upwards by h
glRotatef(120.0,0.0,1.0,0.0); // rotate about the y axis by 120 degrees
glRotatef(30.0,1.0,0.0,0.0); // rotate about the x axis by 30 degrees
FractalTree(0.8*r,0.8*h,iter-1); // draw the next iteration fractal tree
glPopMatrix();
}
}
glPushMatrix();
glTranslatef(0.0,h,0.0);
glRotatef(240.0,0.0,1.0,0.0);
glRotatef(30.0,1.0,0.0,0.0);
FractalTree(0.8*r,0.8*h,iter-1);
glPopMatrix();
z
y
30o
h
x