Vous êtes sur la page 1sur 55

Unit I 2D PRIMITIVES

Part A
1. List out few attributes of output primities. !Ma" 2#1$%
Line style
Color and intensity
Area filling commands
Character attributes
Bundled attributes
2. &'at (o "ou mean b" )*ippin+, !Ma" 2#1$%
Any procedure that identifies those portions of a picture that are either inside or outside of a
specified region of space is referred to as a clipping algorithm or simply clipping. The region
against which an object is clipped is called a clip window.
3. List t'e t"pes of te-t )*ippin+ met'o(s. (No !"#3$ No !"#!%
All&or&none string&clipping
All&or&none character&clipping
Clip the components of indiidual characters
$. &'at is t'e ma.or (ifferen)e between s"mmetri)a* DDA an( simp*e DDA,! Ma" 2#12%
A (i+ita* (ifferentia* ana*"/er !DDA% is used for linear interpolation of ariables oer an
interal between start and end point. 'imple ((A does not re)uire special s*ills for
implementation.
'ymmetrical ((A (digital differential analy+er% generates lines from their differential
e)uations. ,t is important to note that ((As can also be used to generate arcs and other cures.
0. &'at is t'e reuse of )*ippin+, ! Ma" 2#12%
1. &rite (own t'e s'ear transformation matri-. ! 2o 2#12%
34 S'ear

# " "
" # "
" #
x
sh
5 S'ear

# " "
" #
" " #
y
sh
6. &rite (own an" two *ine attributes. !2o 2#11%
Line Type
Line -idth
Line Color
.en and Brush /ptions
7. Differentiate win(ow an( iew port.!2o 2#11%
A portion of a picture that is to be displayed by a window is *nown as window port. The
display area of the part selected or the form in which the selected part is iewed is *nown as
iewport.
8. &'at is meant b" a*iasin+,
The distortion of information due to low fre)uency sampling (0nder sampling% is called
aliasing. -e can improe the appearance of displayed raster lines by applying antialiasing
methods that compensate for the under sampling process.
1#. Define refres' buffer9frame buffer.
The memory area where in picture definition is stored is called 1efresh buffer. This memory area
holds the set of intensity alues for all the screen points. /n a blac* and white system with one bit
per pi2el$ the frame buffer is called a bitmap.
11. Define aspe)t ratio.
,t is a property of ideo monitors. This number gies the ratio of ertical points to
hori+ontal points necessary to produce e)ual&length lines in both directions on the screen.
12. &'at are t'e (isa(anta+es of DDA a*+orit'm,
3 1ound&off error in successie additions of the floating&point increment can cause the
calculated pi2el positions to drift away from the true line path for long line segments.
3 1ounding operations and floating&point arithmetic in procedure are still time&consuming.
1:. . Define Trans*ation.
A translation is applied to an object by repositioning it along a straight line path from one
coordinate location to another. -e translate a two&dimensional point by adding translation
distances$ t2 and ty$ to original coordinate position (2$ y% to moe the point to a new position
(24$ y4%. 24 5 2 6 t2$ y4 5 y 6 ty. The translation distance pair (t2$ ty % is called a translation
ector or shift ector.
1$. Define Rotation.
A !&( rotation is applied to an object by repositioning it along a circular path in the 2y plane.
10. Define S)a*in+.
A scaling transformation alters the si+e of an object. This operation can be carried out for
polygons by multiplying the coordinate alues (2$y% of each erte2 by scaling factors s2 and sy
to produce the transformed coordinates ( 24$ y4 %. 24 5 2. s2$ y4 5 y. sy.
11. Define Ref*e)tion.
A 1eflection is a transformation that produces a mirror image of an object. The mirror image
for a !( reflection is generated relatie to an a2is of reflection by rotating the object #7"
degree about the reflection a2is.
16. &'at is iewin+ transformation,
The mapping of a part of a world&coordinate scene to deice coordinates is referred to as
iewing transformation.
17. &'at are t'e t"pes of ;*ippin+,
o .oint clipping
o Line clipping
o Area clipping
o Cure clipping
o Te2t clipping
18. &rite t'e two p'ases in ;o'en Sut'er*an( a*+orit'm.
,dentify those lines which intersect the clipping window and no need to clipped
.erform the clipping
2#. List out some a(anta+es of DDA a*+orit'm.
,t is simplest the algorithm and it does nto re)uire special s*ill for implemantation
,t is faster method
, t eleminates the multiplication in the e)uation by ma*ing use of raster characteristics
Part <
1. Des)ribe t'e e**ipse (rawin+ a*+orit'm. ! Ma" 2#1$%
Mi(point E**ipse A*+orit'm
#. ,nput r
2
$r
y
and ellipse center (2
c
$y
c
% and obtain the first point on an ellipse centered on the
origin as
(2
"
$y
"
% 5 ("$r
y
%
!. Calculate the initial alue of the decision parameter in region # as
.#
"
5r
y
!
&r
2
!
r
y
6(#89%r
2
!
3. At each 2
*
position in region# starting at *5" perform the following test. ,f .#
*
:"$ the
ne2t point along the ellipse centered on ("$"% is (2
*6#
$ y
*
% and
p#
*6#
5 p#
*
6!

r
y
!
2
* 6#


6 r
y
!

/therwise the ne2t point along the ellipse is (2
*
6#$ y
*
&#% and
p#
*6#
5 p#
*
6!

r
y
!
2
* 6#
& !r
2
!
y
*6#
6 r
y
!

with
!

r
y
!
2
*
6# 5

!

r
y
!
2
*
6 !r
y
!

!

r
2
!
y
*
6# 5

!

r
2
!
y
*
6 !r
2
!

And continue until !ry
!
2;5!r2
!
y
9. Calculate the initial alue of the decision parameter in region ! using the last point (2
"
$y
"
%
is the last position calculated in region #.
p!
"
5 r
y
!
(2
"
6#8!%
!
6r
2
!
(y
o
&#%
!
< r
2
!
r
y
!
=. At each position y* in region !$ starting at *5" perform the following test$ ,f p!
*
;" the
ne2t point along the ellipse centered on ("$"% is (2
*
$y
*&#
% and
p!
*6#
5 p!
*
< !r
2
!
y
*6#
6r
2
!
/therwise the ne2t point along the ellipse is (2
*
6#$y
*
&#% and
p!
*6#
5 p!
*
6 !r
y
!
2
*6#
< !r
2 2
!
y
*6#
6 r
2
!
0sing the same incremental calculations for 2 any y as in region #.
>. (etermine symmetry points in the other three )uadrants.
?. @oe each calculate pi2el position (2$y% onto the elliptical path centered on (2
c
$y
c
% and
plot the coordinate alues
25262
c
$ y5y6y
c

7. 1epeat the steps for region# unit !r
y
!
2;5!r
2
!
y
2. &rite (own an( e-p*ain t'e mi(point )ir)*e (rawin+ a*+orit'm. Assume 1# )m as t'e ra(ius
an( )o4or(inate ori+in as t'e )entre of t'e )ir)*e.!2=V9DE; 2#11> Ma" 2#12%
Mi(point )ir)*e A*+orit'm
#. ,nput radius r and circle center (2c$yc% and obtain the first point on the circumference of the
circle centered on the origin as (2"$y"% 5 ("$r%
!. Calculate the initial alue of the decision parameter as ."5(=89%&r
3. At each 2* position$ starting at *5"$ perform the following test. ,f .* :" the ne2t point along
the circle centered on ("$"% is (2*6#$y*% and .*6#5.*6!2*6#6# /therwise the ne2t point
along the circle is (2*6#$y*&#% and .*6#5.*6!2*6#6#&! y*6# -here !2*6#5!2*6! and
!y*6#5!y*&!
9. (etermine symmetry points in the other seen octants.
=. @oe each calculated pi2el position (2$y% onto the circular path centered at (2c$yc% and plot the
coordinate alues. 25262c y5y6yc
>. 1epeat step 3 through = until 2;5y.
E-amp*e ? Mi(point ;ir)*e Drawin+
Aien a circle radius r5#"
The circle octant in the first )uadrant from 25" to 25y.
The initial alue of the decision parameter is ."5#&r 5 & B
or the circle centered on the coordinate origin$ the initial point is (2"$y"%5("$#"% and initial increment
terms for calculating the decision parameters are !2"5" $ !y"5!" 'uccessie midpoint decision
parameter alues and the corresponding coordinate positions along the circle path are listed in the
following table
* p* (2*6#$
y*&#%
!2*6# !y*6#
" &B (#$#"% ! !"
# &> (!$#"% 9 !"
! &# (3$#"% > !"
3 > (9$B% 7 #7
9 &3 (=$B% #" #7
= 7 (>$7% #! #>
> = (?$?% #9 #9
:. Dis)usses in brief about anti a*iasin+. !2o 2#1:%
$. Line Drawin+ a*+orit'm. !2o 2#12%
Di+ita* Differentia* Ana*"/er !DDA% A*+orit'm
The digital differential analy+er (((A% is a scan&conersion line algorithm based on calculation either
Cy or C2
A line with positie slop$ if the slope is less than or e)ual to #$ at unit 2 interals (C25#% and
compute each successie y alues as "
@A1
B "
@
A m
Dor lines with a positie slope greater than # we reerse the roles of 2 and y$ (Cy5#% and
calculate each succeeding 2 alue as -
@A1
B -
@
A !19m%
,f this processing is reersed$ C25&# that the starting endpoint is at the right "
@A1
B "
@
m.
-hen the slope is greater than # and Cy 5 &# with -
@A1
B -
@
41!19m%.
,f the absolute alue of the slope is less than # and the start endpoint is at the left$ we set C2 5 #
and calculate y alues with "
@A1
B "
@
A m
E-amp*e ? ;onsi(er t'e *ine from !#>#% to !$>1%
2a5"$ ya 5" and 2b59 yb5>
d252b&2a 5 9&" 5 9 and dy5yb&ya5>&"5 >
25" and y5"
9 ; > (false% so$ steps5>
Calculate 2,ncrement 5 d28steps 5 9 8 > 5 ".>> and y,ncrement 5 dy8steps 5>8>5#
'etpi2el(2$y% 5 'etpi2el("$"% ('tarting .i2el .osition%
,terate the calculation for 2,ncrement and y,ncrement for steps(>% number of times
Tabulation of the each iteration
* 2 E
.lotting points
(1ounded to ,nteger%
" "6".>>5".>> "6#5# (#$#%
# ".>>6".>>5#.3! #6#5! (#$!%
! #.3!6".>>5#.B7 !6#53 (!$3%
3 #.B76".>>5!.>9 36#59 (3$9%
9 !.>96".>>53.3 96#5= (3$=%
= 3.36".>>53.B> =6#5> (9$>%
0. ;o'en4 Sut'er*an( *ine )*ippin+ a*+orit'm!Ma"2#12> Ma" 2#1$%
;o'en4Sut'er*an( Line ;*ippin+
This is one of the oldest and most popular line&clipping procedures. The method speeds up the
processing of line segments by performing initial tests that reduce the number of intersections that
must be calculated. Fery line endpoint in a picture is assigned a four digit binary code called a
re+ion )o(e that identifies the location of the point relatie to the boundaries of the clipping
rectangle.
<inar" re+ion )o(es assi+ne( to *ine en( points a))or(in+ to re*atie position wit' respe)t to
t'e )*ippin+ re)tan+*e
1egions are set up in reference to the boundaries. Fach bit position in region code is used to
indicate one of four relatie coordinate positions of points with respect to clip windowG to the left$
right$ top or bottom. By numbering the bit positions in the region code as # through 9 from right to
left$ the coordinate regions are corrected with bit positions as
bit #G left
bit !G right
bit 3G below
bit9G aboe
A alue of # in any bit position indicates that the point is in that relatie position. /therwise the
bit position is set to ". ,f a point is within the clipping rectangle the region code is """". A point
that is below and to the left of the rectangle has a region code of "#"#.
Bit alues in the region code are determined by comparing endpoint coordinate alues (2$y% to clip
boundaries. Bit# is set to # if 2 :2wmin. Dor programming language in which bit manipulation is
possible region&code bit alues can be determined with following two steps.
(#% Calculate differences between endpoint coordinates and clipping boundaries.
(!% 0se the resultant sign bit of each difference calculation to set the corresponding alue in the
region code.
bit # is the sign bit of 2 < 2wmin
bit ! is the sign bit of 2wma2 < 2
bit 3 is the sign bit of y < ywmin
bit 9 is the sign bit of ywma2 & y.
/nce we hae established region codes for all line endpoints$ we can )uic*ly determine which
lines are completely inside the clip window and which are clearly outside.
Any lines that are completely contained within the window boundaries hae a region code of
"""" for both endpoints$ and we accept these lines. Any lines that hae a # in the same bit position
in the region codes for each endpoint are completely outside the clipping rectangle$ and we reject
these lines.
-e would discard the line that has a region code of #""# for one endpoint and a code of "#"#
for the other endpoint. Both endpoints of this line are left of the clipping rectangle$ as indicated by
the # in the first bit position of each region code.
A method that can be used to test lines for total clipping is to perform the logical and operation
with both region codes. ,f the result is not """"$the line is completely outside the clipping region.
Lines that cannot be identified as completely inside or completely outside a clip window by these
tests are chec*ed for intersection with window boundaries.
>. E-p*ain about ref*e)tion! 2o 2#1:%
Ref*e)tion
A reflection is a transformation that produces a mirror image of an object. The mirror image for a
two&dimensional reflection is generated relatie to an a2is of reflection by rotating the object #7"
o
about the reflection a2is. -e can choose an a2is of reflection in the 2y plane or perpendicular to
the 2y plane or coordinate origin
Ref*e)tion of an ob.e)t about t'e - a-is
?.

# " "
" # "
" " #
Ref*e)tion t'e - a-is is a))omp*is'e( wit' t'e transformation matri-
Ref*e)tion of an ob.e)t about t'e " a-is
7.

# " "
" # "
" " #
Ref*e)tion t'e " a-is is a))omp*is'e( wit' t'e transformation matri-
Ref*e)tion of an ob.e)t about t'e )oor(inate ori+in
B.

# " "
" # "
" " #
Ref*e)tion about ori+in is a))omp*is'e( wit' t'e transformation matri-
Unit II :D ;=2;EPTS
Part A
1. Define Sp*ine. !Ma" 2#1$%
A 'pline is a fle2ible strip used to produce a smooth cure through a designated set of points.
2. &'at (o "ou mean b" iewin+,!Ma" 2#1$> Ma" 2#12%
,n three dimensional graphics applications$
& -e can iew an object from any spatial position$ from the front$ from aboe or from
the bac*.
& -e could generate a iew of what we could see if we were standing in the middle of a
group of objects or inside object$ such as a building.
:. Cie t'e +enera* e-pression for <e/ier <ernstein Po*"nomia*. !2o 2#1:%
The n 6 # <ernstein basis po*"nomia*s of degree n are defined as
where is a binomial coefficient.
$. Cie t'e sin+*e point perspe)tie pro.e)tion transformation matri- w'en pro.e)tors are
p*a)es on t'e D a-is. !2o 2#1:%
2H # " " t
2
2
yH 5 " # " t
y
y
+H " " # y
+
"
# " " " # #
=. Differentiate ob*iEue an( ort'o+ona* pro.e)tions. !2o 2#12%
An /1TI/A1A.I,C projection is a parallel projection in which the projectors are
perpendicular to the plane of projection as in.
An /BL,J0F projection is one in which the projectors are other than perpendicular to the
plane of projection.
1. Define Sp*ine )ures. !2o 2#12> 2o 2#11%
The Sp*ine )ure refers to any sections cure formed with polynomial sections satisfying
specified continuity conditions at the boundary of the pieces.
A spline cure is a l representation for which it is easy to build an interface that will allow a
user to design and control the shape of comple2 cures and surfaces.
6. Differentiate para**e* an( perspe)tie pro.e)tions.! Ma" 2#12%
Para**e* pro.e)tion perspe)tie pro.e)tion
Less realistic iew isual effect is similar to human isual system
Coordinates are transferred to iewing plane
along parallel lines
.rojections lines conerge in a point behind
iewing plane
.reseres relatie si+e of objects portions (oesnHt presere relatie si+e but loo*s more
realistic
7. Define Eua(ri) surfa)es.!2o 2#11%
The )uadric surfaces are described with second degree e)uations ()uadratics%. They include
spheres$ ellipsoids$ tori$ parabolas$ and hyperboloids.
8. &'at <oun(ar" representation,
,t describes a 3( object as a set of surfaces that separate the object interior from the
enironment. e.g. polygon facets and spline patches.
1#. Differentiate interpo*ation an( appro-imation sp*ines.
,nterpolation cures are used to digiti+e drawings or to specify animation paths
Appro2imation cures are used as design tools to structure object surfaces
11. Define )one- 'u**.
The cone2 polygon boundary that encloses a set of control points is called the cone2 hull.
12. Spe)if" two a(anta+es of <4sp*ines )ures.
The degree of a B spline polynomial can be set independently of the number of control points.
B&'pline allow local control oer the shape of a spline cure or a surface.
1:. List out an" two properties of <e/ier )ure.
Any cure position is simply the weighted sum of the control point position
The cone2 hull property of a Be+ier ensures that the polynomial smoothly follows the
control points without erratic oscillations.
1$. &'at are t'e properties of <e/ier ;ure,
,t needs only four control points.
,t always passes through the first and last control points.
The cure lies entirely within the cone2 half formed by our control points.
10. &rite about (ept' )uein+.
(epth information is important to identify the iewing direction$ which is the front and which
is the bac* of displayed object.
,t is the method for indicating with wire frame displays is to ary the intensity of objects
according to their distances from the iewing position.
11. &'at is morp'in+,
Transformation of object shape from one from to another is called morphing. @orphing
methods can be applied to any motion or transformation inoling a change in shape.
16. &'at are t'e steps ino*e( in )omputer animation,
'teps in the deelopment of computer animation.
/bject manipulation and rendering
Camera motion
Aeneration of in&betweens.
17. &'at is ba)@ fa)e (ete)tion,
,n solid objects$ there are surfaces which are facing the iewer (front faces% and there are
surfaces which are opposite to the iewer (bac* faces%. These bac* faces contribute to
appro2imately half of the total number of surfaces. 'ince we cannot see these surfaces anyway$
to sae processing time$ we can remoe them before the clipping process.
18. Define (ept' buffer met'o(.
,n this method each scan line is processed$ all polygon surfaces intersecting that line are
e2amined to determine which are isible. Across each scan line$ depth calculations are made
for each oerlapping surfaces to determine which is nearest to the iew plane.
2#. &'at is @e" frame,
/ne of the shape photographs that a film or ideo is made of the shape of an object is *nown
initially and for a small no of other frames called *ey frame.
Part <
1. &rite s'ort note on para**e* an( perspe)tie pro.e)tions !Ma" 2#1$> 2o 2#12> 2o 2#11%
There are two basic types of projection.
# .arallel .rojection & Iere the coordinate positions are transformed to the iew plane along
parallel lines..arallel projection of an object to the iew plane.
.erspectie .rojection < Iere$ object positions are transformed to the iew plane along lines
that conerge to a point called the projection reference point. .erspectie projection of an object
to the iew plane .arallel .rojections
.arallel projections are specified with a projection ector that defines the direction for the
projection lines.-hen the projection in perpendicular to the iew plane$ it is said to be an
/rthographic parallel projection$ otherwise it said to be an /bli)ue parallel projection.
a% Para**e* Pro.e)tion b% Perspe)tie Pro.e)tion
Perspe)tie Pro.e)tions
To obtain perspectie projection of a 3( object$ we transform points along projection lines that meet at
the projection reference point.
,f the projection reference point is set at position +prp along the + a2is and the iew plane is placed at
+p as in fig $ we can write e)uations describing coordinate positions along this perspectie projection
line in parametric form as
2 5 2 & 2u
y 5 y & yu
+ 5 + < (+ < +prp% u
Perspe)tie pro.e)tion of a point P wit' )oor(inates !->">/%. to position !-p> "p>/p% on t'e iew
p*ane.
.arameter u ta*es alues from " to # and coordinate position (2$ y$+% represents any point along the
projection line.
-hen u 5 "$ the point is at . 5 (2$y$+%.
At the other end of the line$ u 5 # and the projection reference point coordinates ("$"$+prp%
/n the iew plane +K 5 +p and +K can be soled for parameter u at this position along the projection
lineG
'ubstituting this alue of u into the e)uations for 2K and yK$ we obtain the perspectie transformation
e)uations.
Lp52M+prp&+p8+&+prpN52Mdp8+&+prpN
Ep5 yM+prp&+p8+&+prpN5yMdp8+&+prpN
where dp 5 +prp < +p is the distance of the iew plane from the projection reference point.
0sing a 3( homogeneous coordinate representation we can write the perspectie projection transformation
(!% in matri2 form as
,n this representation$ the homogeneous factor is
h 5 (+prp&+%8dp
and the projection coordinates on the iew plane are calculated from the homogeneous coordinates as
2p 5 2h 8 h
yp 5 yh 8 h where the original + coordinate alue retains in projection coordinates for depth processing
2. &rite s'ort note on isua*i/ation of (ata for s)a*ar fie*(s!Ma" 2#1$%
:. E-p*ain :D transformations!Ma" 2#1$> Ma" 2#12> 2o 2#12> 2o 2#11%
T'ree Dimensiona* Ceometri) an( Mo(e*in+ Transformations
Aeometric transformations and object modeling in three dimensions are e2tended from two&
dimensional methods by including considerations for the +&coordinate.
Trans*ation
,n a three dimensional homogeneous coordinate representation$ a point or an object is
translated from position . 5 (2$y$+% to position .H 5 (2H$yH$+H% with the matri2 operation.
2H # " " t
2
2
yH 5 " # " t
y
y
+H " " # y
+
+ &&&&&&&&(#% (or% PF B T.P &&&(!%
# " " " # #
.arameters t
2
$ t
y
and t
+
specifying translation distances for the coordinate directions 2$y and +
are assigned any real alues.
The matri2 representation in e)uation (#% is e)uialent to the three e)uations
2H 5 2 6 t
2
yH 5 y 6 t
y
+H 5 + 6 t
+ &&&&&&&&&&
(3%
Translating a point with
translation ector T B !t
-
> t
"
> t
/
%
,nerse of the translation matri2 in e)uation (#% can be obtained by negating the translation distance t
2$
t
y
and t
+
.
This produces a translation in the opposite direction and the product of a translation matri2 and
its inerse produces the identity matri2.
Rotation
To generate a rotation transformation for an object an a2is of rotation must be designed to
rotate the object and the amount of angular rotation is also be specified.
.ositie rotation angles produce counter cloc*wise rotations about a coordinate a2is.
;o4or(inate A-es Rotations
About D a-es
The !( + a2is rotation e)uations are easily e2tended to 3(.
2H 5 2 cos O < y sin O
yH 5 2 sin O 6 y cos O
+H 5 +
.arameters O specifies the rotation angle. ,n homogeneous coordinate form$ the 3( + a2is
rotation e)uations are e2pressed as
2H cosO &sinO " " 2
yH 5 sinO cosO " "
.
y
+H " " # " +
# " " " # #
-hich we can write more compactly as
PF B R
/
!G% . P The Aboe figure illustrates rotation of an object about the +
a2is.
About 3 a-es
The e)uations for an 2&a2is rotation
yH 5 ycosO & +sinO
+H 5 ysinO 6 +cosO
2H 5 2
which can be written in the homogeneous coordinate form
2H # " " " 2
yH 5 " cosO &sinO " y
+H " sinO cosO " +
# " " " # #
(or% PF B R
-
!G%. P The Aboe figure illustrates rotation of an object about the L
a2is
About 5 a-es
The transformation e)uation for a y a2is rotation.
+H 5 +cosO & 2sinO
2H 5 +sinO 6 2cosO
yH 5 y
The matri2 representation for y&a2is rotation is
2H cosO " sinO " 2
yH 5 " # " " y
+H &sinO " cosO " +
# " " " # #
(or% PF B R
"
!G%. P An e2ample of y a2is rotation is shown in aboe figure
An inerse rotation matri2 is formed by replacing the rotation angle O by <O.
Negatie alues for rotation angles generate rotations in a cloc*wise direction$ so the identity
matri2 is produces when any rotation matri2 is multiplied by its inerse.
'ince only the sine function is affected by the change in sign of the rotation angle$ the inerse
matri2 can also be obtained by interchanging rows and columns. (i.e.$% we can calculate the
inerse of any rotation matri2 1 by ealuating its transpose (1
&#
5 1
T
%.
S)a*in+
The matri2 e2pression for the scaling transformation of a position . 5 (2$y$.+% relatie to the
coordinate origin can be written as
2H s
2
" " " 2
yH 5 " s
y
" " y
+H " " s
+
" +
# " " " # #
(or% PF B S.P
where scaling parameters s
2 $
s
y
$ and s
+
are assigned any position alues.
F2plicit e2pressions for the coordinate transformations for scaling relatie to the origin are
2H 5 2.s
2
yH 5 y.s
y
+H 5 +.s
+
'caling an object changes the si+e of the object and repositions the object relaties to the
coordinate origin.
,f the transformation parameters are not e)ual$ relatie dimensions in the object are changed.
The original shape of the object is presered with a uniform scaling (s
2
5

s
y
5 s
+
% .
'caling with respect to a selected fi2ed position (2
f
$ y
f
$ +
f
% can be represented with the
following transformation se)uenceG
#. Translate the fi2ed point to the origin.
!. 'cale the object relatie to the coordinate origin
3. Translate the fi2ed point bac* to its original position. This se)uence of transformation is
shown in the below figure .
=t'er Transformations
Ref*e)tions
A 3( reflection can be performed relatie to a selected reflection a2is or with respect to a
selected reflection plane.
1eflection relatie to a gien a2is are e)uialent to #7"
"
rotations about the a2is.
1eflection relatie to a plane are e)uialent to #7"
"
rotations in 9( space.
-hen the reflection plane in a coordinate plane ( either 2
y
$ 2
+
or y
+
% then the transformation can
be a conersion between left&handed and right&handed systems.
An e2ample of a reflection that conerts coordinate specifications from a right handed system
to a left&handed system is shown in the figure
This transformation changes the sign of + coordinates$ leaes the 2 and y coordinate alues
unchanged.
The matri2 representation for this reflection of points relatie to the 2y plane is
# " " "
1D
+
5 " # " "
" " &# "
" " " #
1eflections about other planes can be obtained as a combination of rotations and coordinate
plane reflections.
S'ears
'hearing transformations are used to modify object shapes.
They are also used in three dimensional iewing for obtaining general projections
transformations.
The following transformation produces a +&a2is shear.
# " a "
'I
+
5 " # b "
" " # "
" " " #
.arameters a and b can be assigned any real alues.
This transformation matri2 is used to alter 2 and y coordinate alues by an amount that
is proportional to the + alue$ and the + coordinate will be unchanged.
Boundaries of planes that are perpendicular to the + a2is are shifted by an amount
proportional to + the figure shows the effect of shearing matri2 on a unit cube for the alues a 5
b 5 #.
$. E-p*ain isib*e surfa)e i(entifi)ation!Ma" 2#1$> 2o 2#1:%
Visib*e Surfa)e I(entifi)ation
A major consideration in the generation of realistic graphics displays is identifying those parts
of a scene that are isible from a chosen iewing position.
;*assifi)ation of Visib*e Surfa)e Dete)tion A*+orit'ms
These are classified into two types based on whether they deal with object definitions directly
or with their projected images
1. =b.e)t spa)e met'o(s? compares objects and parts of objects to each other within the
scene definition to determine which surfaces as a whole we should label as isible.
2. Ima+e spa)e met'o(s? isibility is decided point by point at each pi2el position on the
projection plane. @ost Pisible 'urface (etection Algorithms use image space methods.
<a)@ Ha)e Dete)tion
A point (2$ y$+% is QinsideQ a polygon surface with plane parameters A$ B$ C$ and ( if
A
2
6 B
y
6 C
+
6 ( : "
-hen an inside point is along the line of sight to the surface$ the polygon must be a bac* face .
-e can simplify this test by considering the normal ector 2 to a polygon surface$ which has
Cartesian components (A, B, C). ,n general$ if P is a ector in the iewing direction from the eye
position$ as shown in Dig.$
then this polygon is a bac* face if V . 2 I #
Durthermore$ if object descriptions hae been conerted to projection coordinates and our
iewing direction is parallel to the iewing +

. a2is$ then V B !#> #> V


/
% and V . 2 B V
/
; so that we
only need to consider the sign of C$ the R component of the normal ector N.
,n a right&handed iewing system with iewing direction along the negatie +

a2is in the
below Dig. the polygon is a bac* face if C : ".
Thus$ in general$ we can label any polygon as a bac* face if its
normal ector has a + component alue ;JB #
By e2amining parameter C for the different planes defining an
object$ we can immediately identify all the bac* faces.
0. E-p*ain are sub(iision met'o( of 'i((en surfa)e i(entifi)ation a*+orit'm!2o 2#1:%
1. E-p*ain about :D ob.e)t representation. !Ma" 2#12%
1epresentation schemes for solid objects are diided into two categories as followsG
1. <oun(ar" Representation ! <4reps%
,t describes a three dimensional object as a set of surfaces that separate the object interior from the
enironment. F2amples are polygon facets and spline patches.
2. Spa)e partitionin+ representation
,t describes the interior properties$ by partitioning the spatial region containing an object into a set of
small$ non oerlapping$ contiguous solids(usually cubes%. FgG /ctree 1epresentation
Po*"+on Surfa)es
.olygon surfaces are boundary representations for a 3( graphics object is a set of polygons that
enclose the object interior.
Po*"+on Tab*es
The polygon surface is specified with a set of erte2 coordinates and associated attribute parameters.
Dor each polygon input$ the data are placed into tables that are to be used in the subse)uent processing.
.olygon data tables can be organi+ed into two groupsG Aeometric tables and attribute tables.
Ceometri) Tab*es
Contain erte2 coordinates and parameters to identify the spatial orientation of the polygon surfaces.
Attribute tab*es
Contain attribute information for an object such as parameters specifying the degree of
transparency of the object and its surface reflectiity and te2ture characteristics.
A conenient organi+ation for storing geometric data is to create three listsG
#. The Perte2 Table
Coordinate alues for each erte2 in the object are stored in this table.
!. The Fdge Table
,t contains pointers bac* into the erte2 table to identify the ertices for each polygon
edge.
3. The .olygon Table
,t contains pointers bac* into the edge table to identify the edges for each polygon.
This is shown in fig
Verte- tab*e E(+e Tab*e Po*"+on surfa)e tab*e
P
#
G L
#
$ E
#
$ S
#
F
#
G P
#
$ P
!
'
#
G F
#
$ F
!
$ F
3
P
!
G L
!
$ E
!
$ S
!
F
!
G P
!
$ P
3
'
!
G F
3
$ F
9
$ F
=
$ F
>
P
3
G L
3
$ E
3
$ S
3
F
3
G P
3
$ P
#
P
9
G L
9
$ E
9
$ S
9
F
9
G P
3
$ P
9
P
=
G L
=$
E
=
$ S
=
F
=
G P
9
$ P
=
F> G P
=
$ P
#
Listing the geometric data in three tables proides a conenient reference to the indiidual
components (ertices$ edges and polygons% of each object.
The object can be displayed efficiently by using data from the edge table to draw the
component lines.
F2tra information can be added to the data tables for faster information e2traction. Dor
instance$ edge table can be e2panded to include forward points into the polygon table so that
common edges between polygons can be identified more rapidly.
F
#
G P
#
$ P
!
$ '
#
F
!
G P
!
$ P
3$
'
#
F
3
G P
3
$ P
#
$ '
#
$ '
!
F
9
G P
3
$ P
9
$ '
!
F
=
G P
9
$ P
=
$ '
!
F> G P
=
$ P
#
$ '
!
This is useful for the rendering procedure that must ary surface shading smoothly across the
edges from one polygon to the ne2t. 'imilarly$ the erte2 table can be e2panded so that ertices
are cross&referenced to corresponding edges.
Additional geometric information that is stored in the data tables includes the slope for each
edge and the coordinate e2tends for each polygon. As ertices are input$ we can calculate edge
slopes and we can scan the coordinate alues to identify the minimum and ma2imum 2$ y and +
alues for indiidual polygons.
The more information included in the data tables will be easier to chec* for errors.
'ome of the tests that could be performed by a graphics pac*age areG
#. That eery erte2 is listed as an endpoint for at least two edges.
!. That eery edge is part of at least one polygon.
3. That eery polygon is closed.
9. That each polygon has at least one shared edge.
=. That if the edge table contains pointers to polygons$ eery edge referenced by a
polygon pointer has a reciprocal pointer bac* to the polygon.
6. E-p*ain :D iewin+ !2o 2#12%
T'ree4Dimensiona* Viewin+
,n three dimensional graphics applications$
& -e can iew an object from any spatial position$ from the front$ from aboe or from
the bac*.
& -e could generate a iew of what we could see if we were standing in the middle of a
group of objects or inside object$ such as a building.
Viewin+ Pipe*ine?
,n the iew of a three dimensional scene$ to ta*e a snapshot we need to do the following steps.
#. .ositioning the camera at a particular point in space.
!. (eciding the camera orientation (i.e.$% pointing the camera and rotating it around
the line of right to set up the direction for the picture.
3. -hen snap the shutter$ the scene is cropped to the si+e of the TwindowH of the
camera and light from the isible surfaces is projected into the camera film.
,n such a way the below figure shows the three dimensional transformation pipeline$ from
modeling coordinates to final deice coordinate.
@odeling -orld Piewing
Co&ordinates Co&ordinates Co&ordinates
.rojection (eice.
Co&ordinates co&ordinates
Pro)essin+ Steps
#. /nce the scene has been modeled$ world coordinates position is conerted to iewing
coordinates.
!. The iewing coordinates system is used in graphics pac*ages as a reference for specifying
the obserer iewing position and the position of the projection plane.
3. .rojection operations are performed to conert the iewing coordinate description of the
scene to coordinate positions on the projection plane$ which will then be mapped to the
output deice.
9. /bjects outside the iewing limits are clipped from further consideration$ and the
remaining objects are processed through isible surface identification and surface rendering
procedures to produce the display within the deice iewport.
7. E-p*ain Kua(ri) surfa)es! 2o 2#12%
Kua(ri) Surfa)es
The )uadric surfaces are described with second degree e)uations ()uadratics%.
They include spheres$ ellipsoids$ tori$ parabolids$ and hyperboloids.
Sp'ere
,n Cartesian coordinates$ a spherical surface with radius r centered on the coordinates origin is
defined as the set of points (2$ y$ +% that satisfy the e)uation.
2
!
6 y
!
6 +
!
5 r
!
The spherical surface can be represented in parametric form by using latitude and longitude
angles
2 5 r cosU cosO$ &V8! :5 U:5 V8!
y 5 r cosU sinO$ &V :5 U :5 V
+ 5 rsinU
Modeling
transformation
Viewing
transformation
Projection
Transformation
Work Station
Transformation
The parameter representation in e)uation proides a symmetric range for the angular parameter
O and U.
;ure( Lines an( Surfa)es
(isplays of three dimensional cured lines and surface can be generated from an input set of
mathematical functions defining the objects or from a set of user specified data points.
-hen functions are specified$ a pac*age can project the defining e)uations for a cure to the
display plane and plot pi2el positions along the path of the projected function.
Dor surfaces$ a functional description in decorated to produce a polygon&mesh appro2imation
to the surface.
Kua(ri) Surfa)es
The )uadric surfaces are described with second degree e)uations ()uadratics%.
They include spheres$ ellipsoids$ tori$ parabolids$ and hyperboloids.
Sp'ere
,n Cartesian coordinates$ a spherical surface with radius r centered on the coordinates origin is
defined as the set of points (2$ y$ +% that satisfy the e)uation.
2
!
6 y
!
6 +
!
5 r
!
The spherical surface can be represented in parametric form by using latitude and longitude
angles
2 5 r cosU cosO$ &V8! :5 U:5 V8!
y 5 r cosU sinO$ &V :5 U :5 V
+ 5 rsinU
The parameter representation in proides a symmetric range for the angular parameter O and U.
Torus
Torus is a doughnut shaped object.
,t can be generated by rotating a circle or other conic about a specified a2is.
A torus wit' a )ir)u*ar )ross se)tion )entere( on t'e )oor(inate ori+in
Unit III CRAPLI;S PR=CRAMMI2C
Part A
1. List out basi) primities in open CL.! Ma" 2#1$%
ALW./,NT'
ALWL,NF'
ALWL,NFW'T1,.
ALWL,NFWL//.
ALWT1,ANALF'
ALWT1,ANALFW'T1,
.
ALWT1,ANALFWDAN
ALWJ0A('
ALWJ0A(W'T1,
. ALW./LEA/N
2. Define Me" Hrame.!Ma" 2#1$> 2o 2#12> 2o 2#11%
A *ey frame is detailed drawing of the scene at a certain time in the animation
se)uence.
-ithin each *ey frame$ each object is positioned according to the time for that
frame.
'ome *ey frames are chosen at e2treme positions in the actionR others are spaced so
that the time interal between *ey frames is not too much
:. List out an" four rea* time animation te)'niEues.!2o 2#1:%
o 'tory board layout
o /bject definitions
o Xey&frame specifications
o Aeneration of in&between frames
$. Low are mouse (ata sent to open CL app*i)ation,!2o 2#1:%
The command glu t @ous e Du n c(% is used to specify the callbac* function to use when a
specified button is is a gien state at a certain location.
0. State t'e (ifferen)e between ;M5 an( LSV )o*or mo(e*s.!2o 2#12%
1. &'at are subtra)tie )o*ors,!Ma" 2#12%
,n four&color printing process$ the C@EX colors (Cyan$ @agenta$ Eellow$ and blacX% which are
oerlapped in arious combinations and proportions to produce all other colors. The isible color
is the reflected (and not the retained% color$ and is called 4subtractie4 because its waelength is less
than sum of the waelengths of its constituting colors.
6. &'at (o "ou mean b" tempora* a*iasin+, !Ma" 2#12%
A*iasin+ is an effect that causes different signals to become indistinguishable (or aliases of one
another% when sampled. ,t also refers to the distortion or artifact those results when the signal
reconstructed from samples is different from the original continuous signal.
Aliasing can occur in signals sampled in time$ for instance digital audio$ and is referred to as
tempora* a*iasin+.
7. &'at is animation, !2o 2#11%
Computer animation refers to any time se)uence of isual changes in a scene.
Computer animations can also be generated by changing camera parameters such as
position$ orientation and focal length.
Applications of comput er &generated animation are ent ert ai nment $ adertising$
training and education.
8. &'at is morp'in+,
Transformation of object shape from one from to another is called morphing. @orphing
methods can be applied to any motion or transformation inoling a change in shape.
1#. &'at are t'e steps ino*e( in )omputer animation,
'teps in the deelopment of computer animation.
/bject manipulation and rendering
Camera motion
Aeneration of in&betweens.
11. &'at are t'e properties of *i+'t,
Light is a narrow fre)uency band within the electromagnetic system.
'ince light is an electromagnetic wae$ the arious colors are described in terms of
either fre)uency for the wae length Y of the wae.
Brightness is another property$ which in the perceied intensity of the light.
Another property of light is purity and saturation.
12. Define iew port.
Piew port is the display area on the /penAlHs !( application window.$ which is measured in
pi2els in windows coordinates. The iewport defines the si+e and shape of the display area to
map the projected scene captures by the camera onto the application window.
1:. &'at are t'e )omman(s use( o (raw a point in output s)reen.
glBegin(ALW./,NT'%R
glPerte2!i(#""$="%R
glPerte2!i(#""$#3"%R
glPerte2!i(#="$#3"%R
1$. List out some of t'e )omman(s use( to (raw t'e :D ob.e)ts
.oint & gl.oint'i+e(%
Cude < glut-ireCube(ALdouble si+e%R
'phere < glut-ire'phere(ALdouble radius$ Alint n'lices$Alint n'tic*s%R
10. List out some of t'e )omman(s use( to (raw t'e :D s)enes.
+*Loa(I(entit"!%G loads a 9&by&9 identity matri2 into the current matri2
+*Pus'Matri-!% ? push current matri2 stac*
+*PopMatri-!% ? pop the current matri2 stac*
+*Mu*tMatri- !% ? multiply the current matri2 with the specified matri2
+*Viewport!% ? set the iewport
11. &'at are t'e arious (ata t"pes present in =penCL,
Part <
1. Des)ribe about arious )o*or mo(e*s !Ma" 2#1$> 2o 2#1:> 2o 2#12> Ma" 2#12> 2o
2#11 %
;o*or Mo(e*s
Color @odel is a method for e2plaining the properties or behaior of color within some particular
conte2t. No single color model can e2plain all aspects of color$ so we ma*e use of different models
to help describe the different perceied characteristics of color.
RC< ;o*or Mo(e*
Based on the tristimulus theory of ersion$ our eyes perceie color through the
stimulation of three isual pigments in the cones on the retina.
These isual pigments hae a pea* sensitiity at waelengths of about >3" nm (red%$
=3" nm (green% and 9=" nm (blue%.
By comparing intensities in a light source$ we perceie the color of the light.
This is the basis for displaying color output on a ideo monitor using the 3 color primaries$
red$ green$ and blue referred to as the 1AB color model. ,t is represented in the below figure.
The sign represents blac*$ and the erte2 with coordinates (#$#$#% in white.
Pertices of the cube on the a2es represent the
primary colors$ the remaining ertices represents the
complementary color for each of the primary colors.
The 1AB color scheme is an additie model. (i.e.$%
,ntensities of the primary colors are added to produce
other colors.
Fach color point within the bounds of the cube
can be represented as the triple
(1$A$B% where alues for 1$ A and B are assigned in the range from " to#.
The color CY is e2pressed in 1AB component as
CY 5 1R 6 AC 6 B<
The magenta erte2 is obtained by adding red and blue to produce the triple (#$"$#%
and white at (#$#$#% in the sum of the red$ green and blue ertices.
'hades of gray are represented along the main diagonal of the cube from the origin
(blac*% to the white erte2.
2.0.0 5IK ;o*or Mo(e*
The National Teleision 'ystem Committee (NT'C% color model for forming the composite
ideo signal in the E,J model.
,n the E,J color model$ luminance (brightness% information in contained in the E
parameter$ chromaticity information (hue and purity% is contained into the , and J
parameters.
A combination of red$ green and blue intensities are chosen for the E parameter to yield
the standard luminosity cure.
'ince E contains the luminance information$ blac* and white TP monitors use only the E
signal.
.arameter , contain orange&cyan hue information that proides the flash&tone shading
and occupies a bandwidth of #.= @I+.
.arameter J carries green&magenta hue information in a bandwidth of about ".>
@I+.
An 1AB signal can be conerted to a TP signal using an NT'C encoder which
conerts 1AB alues to E,J alues$ as follows
signal using an NT'C encoder which separates the ideo signal into E,J components$ the
conerts to 1CB alues$ as followsG
;M5 ;o*or Mo(e*
A color model defined with the
primary colors cyan$ magenta$ and yellow
(C@E% in useful for describing color
output to hard copy deices.
,t is a subtractie color model
(i.e.$% cyan can be formed by adding
green and blue light. -hen white light is
reflected from cyan&colored in*$ the
reflected light must hae no red
component. i.e.$ red light is absorbed or
subtracted by the lin*.
@agenta in* subtracts the green component from incident light and yellow subtracts the blue
component.
,n C@E model$ point (#$#$#% represents blac* because all components of the incident
light are subtracted.
The origin represents white light.
F)ual amounts of each of the primary colors produce grays along the main diagonal
of the cube.
A combination of cyan and magenta in* produces blue light because the red and green
components of the incident light are absorbed.
The printing process often used with the C@E model generates a color point with a
collection of 9 in* dotsR one dot is used for each of the primary colors (cyan$ magenta and
yellow% and one dot in blac*.
The conersion from an 1AB representation to a C@E representation is e2pressed as
C # R
M # G
Y # B
-here the white is represented in the 1AB system as the unit column ector.
'imilarly the conersion of C@E to 1AB representation is e2pressed as
R # C
G # Y
B # M
-here blac* is represented in the C@E system as the unit column ector.
LSV ;o*or Mo(e*
The I'P model uses color descriptions that hae a more interactie appeal to a user.
Color parameters in this model are hue (I%$ saturation ('%$ and alue (P%.
The 3( representation of the I'P model is deried from the 1AB cube. The outline of
the cube has the he2agon shape.
The boundary of the he2agon represents the arious hues$ and it is used as the top of the
I'P he2cone.
,n the he2cone$ saturation is measured along a hori+ontal a2is$ and alue is along a ertical
a2is through the center of the he2cone.
Iue is represented as an angle about the ertical a2is$ ranging from "
"


at red through
3>"
"
. Pertices of the he2agon are separated by >"
"
interals.
Eellow is at >"
"
$ green at #!"
"
and cyan opposite red at I 5 #7"
"
. Complementary colors
are #7"
"
apart.
'aturation ' aries from " to #. the ma2imum purity at ' 5 #$ at ' 5 ".!=$ the hue is said to
be one )uarter pure$ at ' 5 "$ we hae the gray scale.
Palue P aries from " at the ape2 to # at the top.
At the top of the he2cone$ colors hae their ma2imum intensity.
-hen P 5 # and ' 5 # we hae the Zpure hues.
-hite is the point at P 5 # and ' 5 ".
LLS ;o*or Mo(e*
IL' model is based on intuitie color parameters used by Te*troni2.
,t has the double cone representation shown in the below figure. The 3 parameters in this
model are called Iue (I%$ lightness (L% and saturation (s%.

Iue specifies an angle about the ertical a2is that locates a chosen hue.

,n this model I 5 O
"
corresponds to Blue.
The remaining colors are specified around the perimeter of
the cone in the same order as in the I'P model.
@agenta is at >"
"
$ 1ed in at #!"
"
$ and cyan in at I 5 #7"
"
.
The ertical a2is is called lightness (L%. At L 5 "$ we hae
blac*$ and white is at L 5 # Aray scale in along the L a2is and
the [purehues\ on the L 5 ".= plane.
'aturation parameter ' specifies relatie purity of a color.
' aries from " to # pure hues are those for which ' 5 # and L
5 ".=
& As ' decreases$ the hues are said to be less pure.
At '5 "$ it is said to be gray scale.
2. Dis)uss in (etai* t'e pro)esses of (rawin+ :D ob.e)ts an( S)enes. ! Ma" 2#1$> 2o 2#12>
Ma" 2#12> 2o 2#11 %
:D =b.e)t
AL0T proides seeral 3( objectsG a sphere$ a cone$ a torus$ the fie platonic solids and the teapot.
Fach is aailable as a wireframe model (one appearing as a collection of wires connected end to end%
and as a solid model with faces that can be shaded.
All are drawn by default centered at the origin.
To use the solid ersion$ replace wire by solid in the functions.
CubeG glut.-ireCube(ALdouble si+e%R
Fach side is of length si+e.
'phereG glut -ire'phere (ALdouble radius$ Alint n'lices$ Alint n'tac*s%R
& n'lices is the number of [orange section\ and nstac*s is the number of dis*s.
& Alternatiely$ n'lices boundries are longitude lines and n'tac*s boundries are latitude lines.
Torus Gglut-ireTorus(ALdouble in1ad$ALdouble out1ad$ Alint n'lices$ Alint n'tac*s%R
TeapotGglut-ireTeapot(ALdouble si+e%R
TetrahedronG glut-ire Tetrahedron(%R
/ctahedronG glut-ire /ctahedron(%R
(odecahedronG glut-ire (odecahedron(%R
,cosahedranG glut-ire ,cosahedran(%R
ConeGglut-ireCone(ALdouble base1ad$ ALdouble height$ Alint n'lices$ Alint n'tac*s%
:D S)ene

/penAL has separate transformation matrices for different graphics features
+*Matri-Mo(e!CLenum mo(e%$ where mode is one ofG
CLNM=DELVIE& & for manipulating model in scene
CLNPR=OE;TI=2 & perspectie orientation CLNTE3TURE
& te2ture map orientation
+*Loa(I(entit"!%G loads a 9&by&9 identity matri2 into the current matri2
+*Pus'Matri-!% ? push current matri2 stac*
+*PopMatri-!% ? pop the current matri2 stac*
+*Mu*tMatri- !% ? multiply the current matri2 with the specified matri2
+*Viewport!% ? set the iewport
E-amp*e ? glPiewport("$ "$ width$ height%R
+*uPerspe)tie!% ? function sets up a perspectie projection matri2.
Hormat ? glu.erspectie(angle$ asratio$ S@,N$ S@AL%R
E-amp*e ? glu.erspectie(>"."$ width8height$ ".#$ #""."%R
+*uLoo @ At!% & iew olume that is centered on a specified eyepoint
E-amp*e G gluLoo*At(3."$ !."$ #."$ "."$ "."$ "."$ "."$ #."$ "."%R
+*utSwap<uffers !% ? glut'wapBuffers swaps the buffers of the current window if double
buffered.
:. Des)ribe t'e met'o(s usin+ in =penCL. ! 2o 2#1:> 2o 2#11%
S. 2o =pen CL Hun)tion Des)ription
"# glut,nit(]argc$ arg%
,t should be called before any other AL0T
routine because it initiali+es the AL0T library
"!
glut,nit(isplay@ode(AL0TW',NALF ^
AL0TW1AB%
To specify the display mode for a window.
"3 glut,nit-indow'i+e(>9"$97"%
A call to g l ut,ni t - i ndow' i +e(% will be used to
specify the si+e$ in pi2els$ of our inital window
"9 glut,nit-indow.osition(#""$#=%
'imilarly$ glut , ni t - in dow.osit i on(% i s used to
specify the screen location for the upper& left
corner of our initial window
"= glutCreate-indow([F2ample\%
To create a window$ the with the preiously set
characteristics (display mode$ si+e$ location$ etc%
"> glut@ainLoop(%
The window is not actually displayed until the
glut@ain L oop(% is entered
Eent (rien pro+rammin+
"? glut(isplayDunc(mydisplay%
,t is a call bac* function and it calls the AL0T for
redisplay.
"7 glut1eshapeDunc(myreshape%
the function that is called wheneer the window is
resi+ed or moed.
"B glutXeyboardDunc(my*eyboard%
Dunction specified and passes as parameters$ the
A'C,, code of the pressed *ey$ and the 2 and y
coordinates of the mouse cursor at the time of the
eent.
#" glut@ouseDunc(mymouse%
The command glu t @ous e Du n c(% is used to
specify the callbac* function to use when a
specified button is is a gien state at a certain
location.
$. E-p*ain t'e animation te)'niEue! Ma" 2#12 %
Animation
Computer animation refers to any time se)uence of isual changes in a scene.
Computer animations can also be generated by changing camera parameters such as
position$ orientation and focal length.
Applications of comput er &generated animation are ent er t ai nment $ adertising$
training and education.
E-amp*e? Adertising animations often transition one object shape into another.
Hrame4b"4Hrame animation
Fach frame of the scene is separately generated and stored. Later$ the frames can be recoded
on film or they can be consecutiely displayed in Qreal&time playbac*Q mode
Desi+n of Animation SeEuen)es
An animation se)uence in designed with the following stepsG
'tory board layout
/bject definitions
Xey&frame specifications
Aeneration of in&between frames.
Stor" boar(
The story board is an outline of the action
,t defines the motion se)uences as a set of basic eents that are to ta*e place.
(epending on the type of animation to be produced$ the story board could consist of a set
of rough s*etches or a list of the basic ideas for the motion.
=b.e)t Definition
An object definition is gien for each participant in the action.

/bjects can be defined in terms of basic shapes such as polygons or splines.
The associated moements of each object are specified along with the shape.
Me" frame
A *ey frame is detailed drawing of the scene at a certain time in the animation se)uence.
-ithin each *ey frame$ each object is positioned according to the time for that frame.
'ome *ey frames are chosen at e2treme positions in the actionR others are spaced so that the
time interal between *ey frames is not too much.
In4betweens
,n betweens are the intermediate frames between the *ey frames.
The number of in between needed is determined by the media to be used to display the
animation.
Dilm re)uires !9 frames per second and graphics terminals are refreshed at the rate of 3" to >"
frames per seconds.
Time interals for the motion are setup so there are from 3 to = in&between for each pair
of *ey frames.
(epending on the speed of the motion$ some *ey frames can be duplicated.
Dor a # min film se)uence with no duplication$ #99" frames are needed.
/ther re)uired tas*s are
& @otion erification
& Fditing
& .roduction and synchroni+ation of a sound trac*.
Cenera* ;omputer Animation Hun)tions
'teps in the deelopment of an animation se)uence are$
/bject manipulation and rendering
Camera motion
Aeneration of in&betweens
Animation pac*ages such as wae front proide special functions for designing the animation
and processing indiiduals objects.
Animation pac*ages facilitate to store and manage the object database.
/bject shapes and associated parameter are stored and updated in the database.
@otion can be generated according to specified constraints using !( and 3(
transformations.
'tandard functions can be applied to identify isible surfaces and apply the rendering
algorithms.
Camera moement functions such as +ooming$ panning and tilting are used for motion
simulation.
Aien the specification for the *ey frames$ the in&betweens can be automatically generated.
Raster Animations
/n raster systems$ real&time animation in limited applications can be generated using raster
operations
'e)uence of raster operations can be e2ecuted to produce real time animation of either !( or
3( objects.
-e can animate objects along !( motion paths using the color&table
transformations.
.redefine the object as successie positions along the motion path$ set
the successie bloc*s of pi2el alues to color table entries.
'et the pi2els at the first position of the object to Zon alues$ and set
the pi2els at the other object positions to the bac*ground color.
The animation is accomplished by changing the color table alues so
that the object is Zon at successie positions along the animation path
as the preceding position is set to the bac*ground intensity.
;omputer Animation Lan+ua+es
Animation functions include a graphics editor$ a *ey frame generator and standard graphics
routines.
The graphics editor allows designing and modifying object shapes$ using spline surfaces$
constructie solid geometry methods or other representation schemes.
'cene description includes the positioning of objects and light sources defining the
photometric parameters and setting the camera parameters.
Action specification inoles the layout of motion paths for the objects and camera.
Xeyframe systems are speciali+ed animation languages designed dimply to generate the
in&betweens from the user specified *eyframes.
.arameteri+ed systems allow object motion characteristics to be specified as part of the
object definitions. The adjustable parameters control such object characteristics as
degrees of freedom motion limitations and allowable shape changes.
'cripting systems allow object specifications and animation se)uences to be defined
with a user input script. Drom the script$ a library of arious objects and motions can be
constructed.
Me"frame S"stems
Fach set of in&betweens are generated from the specification of two *eyframes.
Dor comple2 scenes$ we can separate the frames into indiidual components or objects
called cells$ an acronym from cartoon animation.
Motion Spe)ifi)ation
These are seeral ways in which the motions of objects can be specified in an animation
system.
Dire)t Motion Spe)ifi)ation
Iere the rotation angles and translation ectors are e2plicitly gien.
Then the geometric transformation matrices are applied to transform coordinate positions.
-e can appro2imate the path of a bouncing ball with a damped$ rectified$ sine cure
y (2% 5 A 8 sin(_
2
6 O
"
% 8e
&*2
where A is the initial amplitude$ _ is the angular fre)uency$ O
"
is the phase angle and * is the
damping constant.
Unit IV RE2DERI2C
Part A
1. &'at is f*at s'a(in+, ! Ma" 2#1$%
-hen a face is flat$ li*e a roof and the light sources are distant$ the diffuse light component
aries little oer different points on the roof. ,n such cases we use the same color for eery
pi2el coered by the face. or
Dlat shading is a lighting techni)ue used in 3( computer graphics to shade each polygon of an
object based on the angle between the polygon4s surface normal and the direction of the light
source$ their respectie colors and the intensity of the light source.
2. Low (o "ou a(( te-ture to fa)es, ! Ma" 2#1$%
The realism of an image is greatly enhanced by adding surface te2ture to arious faces of a
mesh object.
The basic techni)ue begins with some te2ture function$ te2ture(s$t% in te2ture space $ which has
two parameters s and t. The function te2ture(s$t% produces a color or intensity alue for each
alue of s and t between "(dar*%and #(light%.
:. &'i)' s'a(in+ met'o( is faster an( easier to )a*)u*ate, &'",!2o 2#1:%
.hong shading is faster because it uses the interpolation points.
$. &'at are t'e t"pes of ref*e)tion an( in)i(ent *i+'t, !2o 2#1:%
'pecularG 'mooth surfaces direct reflected light at opposite angle
(iffusedG 1ough surfaces scatter light in all directions
'preadG 'ome surfaces hae a combination te2ture and smooth surface
(arnish oercoat on paper$ white label on white bottle%
0. Define te-ture. !2o 2#12> Ma" 2#12> 2o 2#11%
,n 3( graphics$ the digital representation of the surface of an object. ,n addition to two&
dimensional )ualities$ such as color and brightness$ a te2ture is also encoded with three&
dimensional properties$ such as how transparent and reflectie the object is. /nce a te2ture has
been defined$ it can be wrapped around any 3&dimensional object. This is called texture
mapping.
1. &'at is a s'a(ow,!2o 2#12%
A s'a(ow is an area where direct light from a light source cannot reach due to obstruction by
an object. ,t occupies all of the space behind an opa)ue object with light in front of it.
6. &rite t'e app*i)ations of te-ure ren(erin+.
1epeating a rendered image multiple times in a scene
'imulating reflection effects $ li*e a mirror or la*e in a scene.
'imulating shadows effects in a scene.
.ost proceeding effects such as motion blur or antialiasing
Compositing a rendering image in to a 3( A0,
Fncounters with irtual objects.
7. &'at is s'a(ow buffer,
An au2iliary second depth buffer$ is employed for each light source.,t contains Qdepth pictureQ for
the scene from the point of iew of the light source.
8. Define a)'romati) *i+'t.
Achromatic light has brightness and no color. ,t is a shade of gray so it is described by a single
alue ie. its intensity.
#". (efine diffuse scattering.
(iffuse scattering occurs when some of the incident light slightly penetrates the surface and is
re&radiated uniformly in all directions. 'cattered light interacts strongly with the surface and so
its color is usually affected by the nature of the surface material.
##. (efine ambient.
-e imagine that a uniform bac*ground glow called ambient light e2ists in the enironment.
The ambient light source spreads in all directions uniformly
#!. -rite the drawbac*s of .hong shading.
1elatiely slow in speed.
@ore computations is re)uired per pi2el.
#3. -hat is bump mapping`
Bump mapping is a techni)ue deeloped by blinn$ to gie a surface a wrin*led or dimpled
appearance without struggling to model each dimple itself.
#9. -rite the applications of rendering te2tures.
1epeating a rendered image multiple times in a scene.
'imulating reflection effects$ li*e a mirror or la*e in a scene.
'imulating shadow effects in a scene.
.ost processing effects$ such as motion blur or ant aliasing.
Compositing a rendered image into a 3( A0,
#=. -rite an /.FNAL function to create a light source.
,n /penAL we can define upto eight light sources. -hich are referred through names
ALWL,AIT"$ ALWL,AIT# and so on. Fach source has properties and must be enabled. Fach
property has a default alue.
#>. Iow can we moe the light source by using /penAL`
Light can be repositioned by suitable uses of gl1otated(% and glTranslated(% functions.
#?. Iow to set material properties by using /penAL`
/penAL proides methods for specifying the arious reflection coefficients. The coefficients
are set with ariations of the function glmaterial and they can be specified for front and bac*
faces.
#7. -rite types of reflection mapping.
Chrome mapping
A rough and blurry image that suggest the surrounding enironment is reflected in the
objects as you would see in an object coated with chrome
Fnironment mapping
. a recogni+able image of the surrounding enironment is scene reflected in the object.
Paluable isual clues are got from such reflections particularly when the object is moing.
Part <
1. Dis)uss about )reation> ren(erin+ te-tures an( (rawin+ s'a(ows for s'a(e( ob.e)ts.
!Ma" 2#1$> 2o 2#12%
Ren(erin+ t'e Te-ture
1endering te2ture in a face D is similar to Aouraud 'hading. ,t proceeds across the face pi2el
by pi2el. Dor each pi2el it must determine the corresponding te2ture coordinates (s$t%$ access
the te2ture and set the pi2el to the proper te2ture color. Dinding the coordinated (s$t% should be
done carefully.
1endering a face in a camera snapshot
The fig shows the camera ta*ing a snapshot of a face D with te2ture pasted onto it and the
rendering in progress. The scan line y is
being filled from 2
left
to 2
right
. Dor each 2 along this
scan line$ we
compute the correct position on the face and from that $ obtain the correct
position (s
a
$ t
a
% within the te2ture.
,ncremental calculation of te2ture coordinates
-e compute (s
left
$t
left
% and (s
right
$t
right
% for each scan line in a rapid
incremental fashion and to
interpolate between these alues$ moing across these scan lines. Linear interpolation produces some
distortion in the te2ture. This distortion is disturbing in an animation when the polygon is rotating.
Correct interpolation produces an te2ture as it should be. ,n an animation this te2ture would appear
to be firmly attached to the moing or rotating face.
Lines in one spa)e map to *ines in anot'er
Affine and projectie transformations presere straightness$ so line
L
e
in eye space projects to line L
s
in screen space$ and similarly the te2els we wish to draw on line L
s
lie along the line L
t
in te2ture
spaces$ which maps to L
e
.
The )uestion is G if we moe in e)ual steps across L
s
on the screen$ how should we step across te2els
along L
t
in te2ture space`
Iow does motion along corresponding lines operate`
The fig. shows a line AB in 3( being transformed into the line ab in 3( by the matri2 @. A maps to
a$ B maps to b.
Simu*atin+ Rou+'ness b" <ump Mappin+
Bump mapping is a techni)ue deeloped by Blinn$ to gie a surface a wrin*led or dimpled
appearance without struggling to model each dimple itself. /ne problem associated with applying
bump mapping to a surface li*e a teapot is that since the model does not contain the dimples $ the
objects outline caused by a shadow does not show dimples and it is smooth along each face.
The goal is to ma*e a scalar function te2ture(s$t% disturb the normal ector at each spot in a
controlled fashion. This disturbance should depend only on the shape of the surface and the te2ture.
The fig. shows in cross section how bump mapping wor*s. 'uppose the surface is represented
parametrically by the function .(u$% and has unit normal ector m(u$%. 'uppose further that the 3(
point at(ua$a% corresponds to te2ture at (ua$a%.
Blinns method simulates perturbing the position of the true surface in the
direction of the normal ector by an amount proportional to the te2ture (ua$a%Rthat is
.(ua$Pa% 5 .(ua$a%6te2ture(ua$a%m(ua$a%.
Digure(a% shows how this techni)ues adds wrin*les to the surface. The disturbed surface has a
new normal ector m(ua$a%at each point. The idea is to use this disturbed
normal as if it were [attached\ to the original undisturbed surface at each point$ as shown in
figure (b%. Blinn has demonstrated that a good appro2imation to m(ua$a% is gien by
m(ua$a% 5m(ua$a%6d(ua$a%
-here the perturbation ector d is gien by
d(ua$a% 5 (m L p

% te2ture
u
< (m L p
u
% te2ture
.
,n which te2ture
u
$ and te2ture

are partial deriaties of the te2ture function with respect to u and
respectiely. Durther p
u
and p

are
partial deriatie of .(u$% with respect to u and $ respectiely. all
functions are ealuated at(ua$Pa%.Note that the perturbation function depends only on the partial
deriaties of the te2ture(%$not on te2ture(%itself.
Ref*e)tion Mappin+
This techni)ue is used to improe the realism of pictures $ particularly animations. The basic idea is
to see reflections in an object
that suggest the world surrounding that object.
The two types of reflection mapping are
;'rome mappin+
A rough and blurry image that suggests the surrounding enironment is reflected in the object
as you would see in an object coated with chrome.
Enironment mappin+
A recogni+able image of the surrounding enironment is seen reflected in the object. Paluable isual
clues are got from such reflections particularly when the object is moing.
2. Dis)uss about a((in+ s'a(ow of ob.e)t an( bui*(in+ )amera in a pro+ram. !Ma" 2#1$>
2o 2#11%
'hadows ma*e an image more realistic. The way one object casts a shadow on another object gies
important isual clues as to how the two objects are positioned with respect to each other. 'hadows
coneys lot of information as such$ you are getting a second loo* at the object from the iew point of
the light source. There are two methods for computing shadowsG
'hadows as Te2ture
Creating shadows with the use of a shadow buffer
S'a(ows as Te-ture
The techni)ue of [painting[ shadows as a te2ture wor*s for shadows that are cast onto a flat surface by
a point light source. The problem is to compute the shape of the shadow that is cast.
<UILDI2C A ;AMERA I2 A PR=CRAM
To hae a finite control oer camera moements$ we create and manipulate our own camera
in a program. After each change to this camera is made$ the camera tells /penAL what the new
camera is.
-e create a Camera class that does all things a camera does. ,n a program we create a
Camera object called cam$ and adjust it with functions such as the followingG
cam.set(eye$ loo*$ up%R 88 initiali+e the camera
cam.slide(&#$ "$ &!%R 88slide the camera forward and to the left cam.roll(3"%R
88 roll it through 3" degree
cam.yaw(!"%R 88 yaw it through !" degree
The Camera class definitionG
class Camera b
priateG
.oint3 eyeR Pector3 u$ $ nR
double iewAngle$ aspect$ near(ist$ far(istR 88iew olume shape
oid set@odelPiew@atri2(%R 88tell /penAL where the camera is
publicG
Camera(%R 88default constructor
oid set(.oint3 eye$ .oint3 loo*$ Pector3 up%R 88li*e gluLoo*At(%
oid roll(float$ angle%R 88roll it
oid pitch(float$ angle%R 88 increase the pitch
oid yaw(float$ angle%R 88yaw it
oid slide(float del0$ float delP$ float delN%R 88slide it oid set'hape(float Ang$ float
asp$ float near($ float far(%R
cR
H*"in+ t'e )amera
The user flies the camera through a scene interactiely by pressing *eys or clic*ing the
mouse. Dor instance$ pressing u will slide the camera up some amount pressing y will yaw the camera
to the left pressing f will slide the camera forward
The user can see different iews of the scene and then changes the camera to a better iew
and produce a picture. /r the user can fly around a scene ta*ing different snapshots. ,f the snapshots
are stored and then played bac*$ an animation is produced of the camera flying around the scene.
There are si2 degrees of freedom for adjusting a cameraG ,t can be slid in three dimensions
and it can be rotated about any of three coordinate a2es.
S*i(in+ t'e ;amera
'liding the camera means to moe it along one of its own a2es that is$ in the u$ and n
direction without rotating it. 'ince the camera is loo*ing along the negatie n a2is$ moement along n
is forward or bac*. @oement along u is left or right and along is up or down.
To moe the camera a distance ( along its u a2is$ set eye to eye 6 (u. for conenience$ we
can combine the three possible slides in a single functionG
slide(del0$ delP$ delN%
slides the camera amount del0 along u$ delP along and delN along n.
oid Camera G G slide(float del0$ float delP$ float delN%
b
eye.2 65 del0 a u.2 6 delP a .2 6 delN a n.2R eye.y 65 del0 a
u.y 6 delP a .y 6 delN a n.yR eye.+ 65 del0 a u.+ 6 delP a .+
6 delN a n.+R set@odelPiew@atri2(%R
c
Rotatin+ t'e ;amera
1oll$ pitch and yaw the camera $ inoles a rotation of the camera about one of its own a2es.
To roll the camera we rotate it about its own n&a2is. This means that both the directions u
and must be rotated
oid Camera GG roll (float angle%
b 88 roll the camera through angle degrees
float cs 5 cos (3.#9#=B!>=8#7" a angle%R float sn 5 sin
(3.#9#=B!>=8#7" a angle%R Pector3 t 5 uR 88remember
old u
u.set(cs a t.2 < sn a .2 $ cs a t.y < sn a .y$ cs a t.+ < sn a .+%R .set(sn a t.2 6 cs a
.2 $ sn a t.y 6 cs a .y$ sn a t.+ 6 cs a .+%R set@odelPiew@atri2(%R
c
The Camera class can be used with /penAL to fly a camera through a scene. The scene
consists of only a teapot. The camera is a global object and is set up in main(%. -hen a *ey is
pressed myXeyboard(% is called and the camera is slid or rotated$ depending on which *ey was
pressed.
Dor instance$ if . is pressed$ the camera is pitched up by # degree. ,f CT1L D is
pressed $ the camera is pitched down by # degree. After the *eystro*e has been processed$
glut.ost1edisplay(% causes my(isplay(% to be called again to draw the new picture.
This application uses double buffering to produce a fast and smooth transition between one
picture and the ne2t. Two memory buffers
are used to store the pictures that are generated. The display switches from showing one buffer to
showing the other under the control of glut'wapBuffers(%
:. Dis)uss t'e pro)esses of a((in+ te-ture to fa)es of t'e rea* ob.e)ts. !2o 2#1:> 2o 2#11%
A((in+ Te-ture to Ha)es
The realism of an image is greatly enhanced by adding surface te2ture to arious faces of a mesh
object. The basic techni)ue begins with some te2ture function$ te-ture!s>t% in te-ture spa)e $ which
has two parameters s and t. The function te2ture(s$t% produces a color or intensity alue for each alue
of s and t between "(dar*%and #(light%. The two common sources of te2tures are
Bitmap Te2tures
.rocedural Te2tures
<itmap Te-tures Te2tures are formed from bitmap representations of images$ such as
digiti+ed photo. 'uch a representation consists of an array t-trP)QPrQ of color alues. ,f the array has C
columns and 1 rows$ the indices c and r ary from " to C&# and 1&# resp.$. The function te2ture(s$t%
accesses samples in the array as in the codeG
Color3 te2ture (float s$ float t% b return t2trM (int% (s a C%NM(int% (t a 1%NR c -here Color3 holds an 1AB
triple. F2ampleG ,f 159"" and C5>""$ then the te2ture (".!>#$ ".?73% ealuates to t2trM#=>NM3#3N. Note
that a ariation in s from " to # encompasses >"" pi2els$ the ariation in t encompasses 9"" pi2els.
To aoid distortion during rendering $ this te2ture must be mapped onto a rectangle
with aspect ratio >89. .rocedural Te2tures Te2tures are defined by a mathematical function or
procedure. Dor e2ample a spherical shape could be generated by a functionG
float fa*esphere( float s$ float t% b float r5 s)rt((s&".=% a (s&".=%6 (t&".=% a (t&".=%%R if (r : ".3%
return #&r8".3R 88sphere intensity else return ".!R 88dar* bac*ground c This function aries from
#(white% at the center to " (blac*% at the edges of the sphere.
Paintin+ t'e Te-tures onto a H*at Surfa)e Te2ture space is flat so it is simple to paste te2ture on a
flat surface.
Mappin+ te-ture onto a p*anar po*"+on
The fig. shows a te2ture image mapped to a portion of a planar polygon$D. -e need to specify how to
associate points on the te2ture with points on D. ,n /penAL we use the function +*Te-;oor(2f!%
To associate a point in te2ture space .i5(si$ti% with each erte2 Pi of the face. the function
glTe2Coord!f(s$t%sets the current te2ture coordinate to (s$y%. All calls to +*Verte-:f!% is called after a
call to glTe2Coord!f(%$ so each erte2 gets a new pair of te2ture coordinates. F2ample to define a
)uadrilateral face and to position a te2ture on it$ we send /penAL four te2ture coordinates and four
3( points$ as followsG
glBegin(ALWJ0A('%R 88defines a )uadrilateral face glTe2Coord!f("." $"."%R glPerte23f(#." $ !.=$
#.=%R
glTe2Coord!f("." $".>%R
glPerte23f(#." $ 3.?$ #.=%R
glTe2Coord!f(".7 $".>%R
glPerte23f(!." $ 3.?$ #.=%R
glTe2Coord!f(".7 $"."%R
glPerte23f(!." $ !.=$ #.=%R
glFnd(%R @apping a ')uare to a 1ectangle
The fig. shows the a case where the four corners of the te2ture s)uare are associated with the four
corners of a rectangle. ,n this e2ample$ the te2ture is a >9"&by&97" pi2el bit map and it is pasted onto a
rectangle with aspect ratio >9"897"$ so it appears without distortion. Pro(u)in+ repeate( te-tures
$. ;ompare f*at an( smoot' s'a(in+ wit' respe)t to t'eir )'ara)teristi)s. !2o 2#1:> 2o
2#12%
0. E-p*ain about s'a(in+ mo(e*s ! 2o 2#12 %
S'a(in+ Mo(e*s
The mechanism of light reflection from an actual surface is ery complicated it depends
on many factors. 'ome of these factors are geometric and others are related to the
characteristics of the surface.
A shading model dictates how light is scattered or reflected from a surface. The shading
models described here focuses on achromatic light
Achromatic light has brightness and no color$ it is a shade of gray so it is described by a
single alue its intensity.
A shading model uses two types of light source to illuminate the objects in a scene G
point *i+'t sour)es an( ambient *i+'t.
,ncident light interacts with the surface in three different waysG
o 'ome is absorbed by the surface and is conerted to heat.
o 'ome is reflected from the surface
o 'ome is transmitted into the interior of the object
'ome amount of the reflected light traels in the right direction to
1each the eye causing the object to be seen. The amount of light that reaches the eye depends
on the orientation of the surface$ light and the obserer. There are two different types of
reflection of incident light
(iffuse scattering occurs when some of the incident light slightly penetrates the surface and
is re&radiated uniformly in all directions. 'cattered light interacts strongly with the surface
and so its color is usually affected by the nature of the surface material
'pecular reflections are more mirrorli*e and highly directional.
The total light reflected from the surface in a certain direction is the sum of the
diffuse component and the specular component.
Ceometri) In+re(ients for Hin(in+ Ref*e)te( Li+'t
-e need to find three ectors in order to compute the diffuse and specular components. The
below fig. shows three principal ectors ( s$ m and % re)uired to find the amount of light that
reaches the eye from a point .. ,mportant directions in computing the reflected light
#. The normal ector $ m $ to the surface at ..
!. The ector from . to the iewers eye.
3. The ector s from . to the light source.
The angles between these three ectors form the
basis of computing light intensities. These angles are
normally calculated using world coordinates
Low to ;ompute t'e Diffuse ;omponent
'uppose that a light falls from a point source onto one side of a face $ a fraction of it is re&
radiated diffusely in all directions from this side. 'ome fraction of the re&radiated part reaches the
eye$ with an intensity denoted by ,
d
.
An important property assumed for diffuse scattering is that it is independent of the direction
from the point .$ to the location of the i ewerHs eye. This i s called omnidirectional
scat t eri ng$
because scattering is uniform in all directions. Therefore ,
d
is
independent of the
angle between m and .
/n the other hand the amount of light that illuminates the face does not depend on the
orientation of the face relatie to the point source. The amount of light is proportional to the area of
the face that it sees. The brightness depends on the area of the face that it sees
Dig (a% shows the cross section of a point
source illuminating a face ' when m is
aligned with s.
Dig (b% the face is turned partially away
from the light source through angle O.
The area subtended is now only cos(O% $ so that the brightness is reduced of ' is reduced by this
same factor. This relationship between the brightness and surface orientation is called LambertFs *aw
cos(O% is the dot product between the normali+ed ersions of s and m.
Therefore the strength of the diffuse componentG
s.m
,
d
5 ,
s
d
d
s m
,
s
is the intensity of the light source and d
d
is the diffuse
reflection coefficient. ,f the facet is
aimed away from the eye this
dot product is negatie so we need to ealuate ,
d
to ". A more
precise computation of the diffuse component is G

s.m
0
,
d
5 ,
s
d
d
ma2
s m
The reflection coefficient d
d
depends on the waelength of the
incident light $ the angle O and arious
physical properties of the surface.
Spe)u*ar Ref*e)tion
1eal objects do not scatter light uniformly in all directions and so a specular component is
added to the shading model. 'pecular reflection causes highlights which can add reality to a picture
when objects are shinny. The behaior of specular light can be e2plained with .hong model
P'on+ Mo(e*
,t is easy to apply and the highlights generated by the phong model gien an plasticli*e
appearance $ so the phong model is good when the object is made of shinny plastic or glass.
The .hong model is less successful with objects that hae a shinny metallic surface.
Dig a% shows a situation where light from a source impinges on a surface and is reflected in different
directions Dig (b% shows this with beam patterns.
,n this model we discuss the amount of light reflected is greatest in the direction of perfect
mirror reflection $ r$ where the angle of incidence O e)uals the angle of reflection. This is the direction
in which all light would trael if the surface were a perfect mirror. At the other nearby angles the
amount of light reflected diminishes rapidly
Dig(c% shows how to )uantify this beam pattern effect . The direction r of perfect reflection
depends on both s and the normal ector m to the surface$ according to
r 5 &s 6 !
s.m
m m ( the mirror < reflection direction%
Dor surfaces that are shiny but are not true mirrors$ the amount of light reflected falls
off as the angle U between r and increases. ,n .hong model the U is said to ary
as some power f of the cosine of U i.e.$ ! )os !R %%
f
in which f is chosen e2perimentally and
usually lies between # and !"".
Unit V Hra)ta*s
Part A
1. &'at are piano )ures, !Ma" 2#1$%
'ome cures are e2act l y se*f4simi*ar$ whereby i f a regi on i s enlarged the enlargement
loo*s e2actly li*e the original.
2. &'at is t'e use of fra)ta*s in +rap'i)s app*i)ations, !Ma" 2#1$%
A Aeometric pattern that is repeated at eer smaller scales to produce irregular shapes and
surfaces that cannot be represented by classical geometry. Dractals are used especially in
computer modeling of irregular patterns and structures in nature.
@andelbrot sets
eulia sets
:. Low ob.e)ts are mo(e*e( usin+ )onstru)tie so*i( +eometri) te)'niEue.!2o 2#1:%
A ray tracing method to combine simple shapes to more comple2 ones is *nown as
constructie 'olid Aeometry (C'A%. Arbitrarily comple2 shapes are defined by set operations on
simpler shapes in a C'A. /bjects such as lenses and hollow fish bowls$ as well as objects with
holes are easily formed by combining the generic shapes. 'uch objects are called compound$
Boolean or C'A objects.
$. List (own t'e properties of piano )ures.!2o 2#12%
,f a cure is not injectie$ then one can find two intersecting sub cures of the cure$
each obtained by considering the images of two disjoint segments from the cure4s
domain
A non&self&intersecting continuous cure cannot fill the unit s)uare because that will
ma*e the cure a homeomorphism from the unit interal onto the unit s)uare.
space&filling cure can be (eerywhere% self&crossing if its appro2imation cures are
self&crossing.
0. &rite (own some of <oo*ean operations on ob.e)ts.!2o 2#12%
Union 4 e+. 15C
#
0 C
!
0 C
3
0 C
9
.
Interse)tion 4 e+. L5'
#
f'
!
Differen)e 4 e+ L5'
#
&'
!
1. Define fra)ta*s! Ma" 2#12> 2o 2#11%
A cure or geometrical figure$ each part of which has the same statistical character as the
whole. They are useful in modeling structures (such as snowfla*es% in which similar patterns
recur at progressiely smaller scales$ and in describing partly random or chaotic phenomena
such as crystal growth and gala2y formation.
6. &'at is Ou*ia sets,! Ma" 2#12%
The eulia set is named after the Drench mathematician Aaston eulia who inestigated their
properties circa #B#= and culminated in his famous paper in #B#7. -hile the eulia set is now
associated with a simpler polynomial$ eulia was interested in the iteratie properties of a more
general e2pression$ namely +
9
6 +
3
8(+&#% 6 +
!
8(+
3
6 9 +
!
6 =% 6 c.
The eulia set is now associated with those points + 5 2 6 iy on the comple2 plane for which the
series +
n6#
5 +
n
!
6 c does not tend to infinity. c is a comple2 constant$ one gets a different eulia
set for each c. The initial alue +
"
for the series is each point in the image plane. ,n the broader
sense the e2act form of the iterated function may be anything$ the general form being +
n6#
5
f(+
n
%$ interesting sets arise with nonlinear functions f(+%.
7. Differentiate Man(e*brot an( Ou*ia sets.!2o 2#11%
The @andelbrot set is the two dimensional subset of this set that results if you always pic*
/
#
5" and allow ) to ary. (The mathematical definition is rather more comple2$ than this$ but it
turns out to be e)uialent%.
The eulia set for a comple2 number @ is the two dimensional set that results if you always pic*
)B@ and allow /
#
to ary. ,n fact this is what is called the QfilledQ eulia set. /fficially spea*ing
the eulia set is the boundary between points that tend to infinity$ and those that don4t.
8. List out some properties of fra)ta*s.
'elf similar
Dormatted by iteration
Dractional dimension
Dorm is e2tremely irregular or fragmented
1#. &'at is ra" tra)in+,
1ay tracing also called as ray casting $ it is a techni)ue for generating an image by tracing the bath
of light through pi2els in an image and simulating the effects of its encounters with irtual objects.
11. &'at are t'e t'ree t"pes of se*f simi*arit" foun( in fra)ta*s,
F2actly self similar
Juasi self similarity
'tatistically self similar
12. &'at is @nown as L s"stem,
L system (also *nown as Lin denmayer systems or parallel string & rewrite systems% is a simple
approach to generate a large number of comple2 cures by refining the line segments based on a
simple set of rules.
1:. Cie t'e ru*es for (ra+on )ures.
The rules that used L and E for dragon cures
D ` D
L ` L6ED6
E`&DL&E
Atom5DL
D means Qdraw forwardQ
&means Qturn left B" degreeQ
6 means turn right B" degreeQ
1$. &'at is @nown as surfa)e te-ture,
'urface te2ture$ also *nown surface finish$ is the characteristics of a surface in which computer
generated images is made more li*ely and realistic by paining te2ture on arious surfaces.
#=. -hat is computer graphics realism`
The creation of realistic picture in computer graphics is *nown as realism. ,t is important in
fields such as simulation$ design$ entertainment$ adertising$ research etc.
#>. -hat is turtle graphics program`
The turtle program is a robot that can moe in !( and it has a pencil for drawing. The turtle is
defined by the following parameters. .osition of the turtle(2$y%. Ieading of the turtle " the
angle from 2 a2is.
#?. -hat is super sampling.
Anti aliasing can be performed by sampling a scene at more points called super sampling.
#7. (efine constructie solid geometry(C'A%
Applying ray tracing method for comple2 shapes is called as C'A. According to C'A comple2
shapes are defined by Boolean or set operations.
#B. -rite type of te2turing.
,nage Te2ture < A !( image is pasted onto each surface of the object.
'olid Te2ture < the object is considered to be cured out of a bloc* of some material that itself
has te2turing.
!". -hat is *och cure`
The *och cure can be drawn by diiding line into 9 e)ual segments with scaling factor #83 and
middle ! segments are so adjusted that they form adjustments sides of an e)ual triangle.
Part <
1. E-p*ain about )reation of ima+e b" iterate( fun)tions. ! Ma" 2#1$ %
2. &rite about Man(e*brot an( Ou*ia sets ! Ma" 2#1$> 2o 2#1:> Ma" 2#12> 2o 2#12 %
c
MA2DEL<R=T SET
Araphics proides a powerful tool for studying a fascinating collection of sets that are
the most complicated objects in mathematics.
eulia and @andelbrot sets arise from a branch of analysis *nown as iteration theory$ which as*s what
happens when one iterates a function endlessly. @andelbrot used computer graphics to perform
e2periments.
@andelbrot 'ets and ,terated Dunction 'ystems
A iew of the @andelbrot set is shown in the below figure. ,t is the blac* inner
portion$ which appears to consist of a cardoid along with a number of wartli*e circles glued to it.
,ts border is complicated and this comple2ity can be e2plored by +ooming in on
a portion of the border and computing a close up iew. Fach point in the figure is shaded or colored
according to the outcome of an e2periment run on an ,D'.
The ,D' uses the simple function
f(+% 5 +
!
6 c
the system generates the se)uence of
alues or orbit
d
#
5 (s%
!
6 c
d
!
5 ((s%
!
6 c%
!
6 c
d
3
5 (((s%
!
6 c%
!
6 c%
!
6 c
d
9
5 ((((s%
!
6 c%
!
6 c%
!
6 c%
!
6 c
The orbit depends on two ingredients
the starting point s
the gien alue of c
The ,D' wor*s well with both comple2 and real numbers. Both s and c are comple2 numbers and
at each iteration we s)uare the preious result and add c. ')uaring a comple2 number + 5 2 6 yi
yields the new comple2 number
( 2 6 yi%
!
5 (2
!
< y
!
% 6 (!2y%
i
haing real part e)ual to 2
!
< y
!
and imaginary part e)ual to
!2y.
,t is useful to e2amine the fi2ed points of the system f(.% 5(.%! 6 c . The behaior of the
orbits depends on these fi2ed points that is those comple2 numbers + that map into themseles$ so
that +
!
6 c 5 +. This gies us the )uadratic e)uation +
!
< + 6 c 5 " and the fi2ed points of the system
are the two solutions of this e)uation$ gien by
p
6
$ p
&
5
# #
! 9
,f an orbit reaches a fi2ed point$ p its gets trapped there foreer. The fi2ed point can
be characteri+ed as attracting or repelling. ,f an orbit flies close to a fi2ed point p$ the ne2t point
along the orbit will be forced
closer to p if p is an attracting fi2ed point
farther away from p if p is a repelling a fi2ed point.
,f an orbit gets close to an attracting fi2ed point$ it is suc*ed
into the point. ,n contrast$ a repelling fi2ed point *eeps the orbit away from it.
Definin+ t'e Man(e*brot Set
The @andelbrot set considers different alues of c$ always using the starting point s
5". Dor each alue of c$ the set reports on the
nature of the orbit of "$ whose first few alues are as followsG
orbit of "G "$ c$ c
!
6c$ (c
!
6c%
!
6c$ ((c
!
6c%
!
6c%
!
6c$gg..
Dor each comple2 number c$ either the orbit is finite so that how far along the orbit
one goes$ the alues remain finite or the orbit e2plodes that is the alues get larger without limit.
The @andelbrot set denoted by @$ contains just those alues of c that result in finite orbitsG
The point c is in @ if " has a finite orbit.
The point c is not in @ if the orbit of " e2plodes.
Definition?
The @andelbrot set @ is the set of all comple2 numbers c that produce a finite
orbit of ".
,f c is chosen outside of @$ the resulting orbit e2plodes. ,f c
is chosen just beyond the border of @$ the orbit usually thrashes around the plane and goes to
infinity.
,f the alue of c is chosen inside @$ the orbit can do a ariety of things. Dor some cHs it goes
immediately to a fi2ed point or spirals into such a point.
OULIA SETS
Li*e the @andelbrot set$ eulia sets are e2tremely complicated sets of points in the
comple2 plane. There is a different eulia
set$ denoted e
c
for each alue of c. A closely related ariation
is the filled& in eulia set$ denoted by X
c$
which is easier to define.
T'e Hi**e(4In Ou*ia Set M
)
,n the ,D' we set c to some fi2ed chosen alue and e2amine what happens for different
starting point s. -e as* how the orbit of starting point s behaes. Fither it e2plodes or it doesnHt.
,f it is finite $ we
say the starting point s is in X
c
$ otherwise s lies outside of X
c
.
Definition?
The filled&in eulia set at c$ X
c
$ is the set of all starting points
whose orbits are finite.
-hen studying X
c
$ one chooses a single alue for c and considers different starting
points. X
c
should be always symmetrical
about the origin$ since the orbits of s and <s become
identical after one iteration.
Drawin+ Hi**e(4in Ou*ia Sets
A starting point s is in X
c
$ depending on whether its orbit is
finite or e2plodes$ the
process of drawing a filled&in eulia set is almost similar to @andelbrot set. -e choose a window in
the comple2 plane and associate pi2els with points in the window. The pi2els correspond to different
alues of the starting point s. A single alue of c is chosen and then the orbit for each pi2el position
is e2amined to see if it e2plodes and if so$ how )uic*ly does it e2plodes.
.seudocode for drawing a region of the Dilled&in eulia set
for(j5"R j:rowsR j66%
for(i5"R i:colsR i66%
b
find the corresponding s alue in e)uation (=%
estimate the dwell of the orbit
find Color determined by estimated dwell set.i2el( j $ *$
Color%R
c
The dwell(% must be passed to the starting point s as well as
c. @a*ing a high&
resolution image of a X
c
re)uires a great deal of
computer time$ since a comple2 calculation is
associated with eery pi2el.
:. &rite s'ort note on ra" tra)in+ ! Ma" 2#1$> 2o 2#1: %
,n computer graphics$ ray tracing is a techni)ue for generating an image by tracing the path of light
through pi2els in an image plane and simulating the effects of its encounters with irtual objects .1ay
tracing proides a powerful approach to rendering scenes.
1ay Tracing is a global illumination based rendering method for generating realistic images on the
computer
,n ray tracing$ a ray of light is traced in a bac*wards direction. -e start from the eye or camera and
trace the ray through a pi2el in the image plane into the scene and determine what it intersects the pi2el
is then set to the color alues returned by the ray.
,f the ray misses all objects$ then that pi2el is shaded the bac*ground color.
Horwar( Ra" tra)in+
1ays from light source bounce of objects before reaching the camera
Computational wastage
<a)@war( Ra" tra)in+
Trac* only those rays that finally made it to the camera.
Ra" ;astin+
Pisible surfaces of objects are found by throwing (or casting% rays of light from the iewer into the
scene
Ra" Tra)in+
F2tension to 1ay casting 1ecursiely cast rays from the points of intersection.
I2TERSE;TI2C RA5S &ITL =TLER PRIMITIVES
Dirst the ray is transformed into the generic coordinates of the object and then the arious
intersections with the generic object are computed.
Interse)tin+ wit' a SEuare
The generic s)uare lies in the +5" plane and e2tends from &# to # in both 2 and y. The s)uare can be
transformed into any parallelogram positioned in space$ so it is often used in scenes to proide this$
flat surfaces such as walls and windows. The function hit(#% first finds where the ray hits the
generic plane and then test whether this hit spot also lies within the s)uare.
Interse)tin+ wit' a Tapere( ;"*in(er
The side of the cylinder is part of an infinitely long wall with a radius of L at +5"$and a small radius
of ' at +5#.This wall has the implicit form as
D(2$ y$ +%52! 6 y!& (# 6 (' & #% +%!$ for " : + : #
,f '5#$ the shape becomes the generic cylinder$ if '5" $ it becomes the generic cone. -e deelop a
hit (% method for the tapered cylinder$ which also proides hit(% method for the cylinder and cone.
Interse)tin+ wit' a ;ube !or an" ;one- Po*"'e(ron%
The cone2 polyhedron$ the generic cube deseres special attention. ,t is centered at the origin and
has corner at (h#$ h#$ h#% using all right combinations of 6# and &#.Thus$its edges are aligned with
coordinates a2es$ and its si2 faces lie in the plan.
The generic cube is important for two reasons.
A large ariety of intersecting bo2es can be modeled and placed in a scene by applying an affine
transformation to a generic cube. Then$ in ray tracing each ray can be inerse transformed into the
generic cubes coordinate system and we can use a ray with generic cube intersection routine.
$. &rite s'ort note on <oo*ean operations on ob.e)ts ! Ma" 2#1$> 2o 2#1: %
A ray tracing method to combine simple shapes to more comple2 ones is *nown as
constructie 'olid Aeometry (C'A%. Arbitrarily comple2 shapes are defined by set operations
on simpler shapes in a C'A. /bjects such as lenses and hollow fish bowls$ as well as objects
with holes are easily formed by combining the generic shapes. 'uch objects are called
compound$ Boolean or C'A objects.
Two compound objects build from spheres. The intersection of two spheres is shown as a lens
shape. That is a point in the lens if and only if it is in both spheres. L is the intersection of the
'
#
and '
!
is written as L5'
#
f'
!
The difference operation is shown as a bowl. A point is in the difference of sets A and B$
denoted A&B$ if it is in A and not in B. Applying the difference operation is analogous to
remoing material to cutting or carrying. The bowl is specified by B5('
#
&'
!
%&C
The solid globe$ '
#
is hollowed out by remoing all the points of the inner sphere$ '
!
$forming a
hollow spherical shell. The top is then opened by remoing all points in the cone C.
A point is in the union of two sets A and B$ denoted A0B$ if it is in A or in B or in both.
Dorming the union of two objects is analogous to gluing them together.
The union of two cones and two cylinders is shown as a roc*et.
15C
#
0 C
!
0 C
3
0 C
9
.
Cone C
#
resets on cylinder C
!
.Cone C
3
is partially embedded in C
!
and resets on the fatter
cylinder C
9
.
Ra" Tra)in+ ;S; ob.e)ts
1ay traces objects that are Boolean combinations of simpler objects. The ray inside lens L from t
3
to t
!
and the hit time is t
3
.,f the lens is opa)ue$ the familiar shading rules will be applied to find
what color the lens is at the hit spot. ,f the lens is mirror li*e or transparent spawned rays are
generated with the proper directions and are traced.
1ay first stri*es the bowl at t
#
$ the smallest of the times for which it is in '
#
but not in either '
!
or
C. 1ay ! on the other hand$ first hits the bowl at t
=
. Again this is the smallest time for which the
ray is in '
#
$ but in neither the other sphere nor the cone. The hits at earlier times are hits with
components parts of the bowl$ but not with the bowl itself.
Data Stru)ture for <oo*ean ob.e)ts
'ince a compound object is always the combination of two other objects say obj
#
/. /bj
!
$ or
binary tree structure proides a natural description.
Interse)tin+ Ra"s wit' <oo*ean =b.e)ts
-e need to be deelop a hit(% method to wor* each type of Boolean object. The method must
form inside set for the ray with the left sub tree$ the inside set for the ray with the right sub tree$
and then combine the two sets appropriately.
bool ,ntersection BoolGGhit(ray in ,ntersection ] inter%
b
,ntersection lftinter$rtinterR
if (ray misses the e2tends%return falseR
if (C% left i;hit(r$lftinter%^^((righti;hit(r$rtinter%%%
return falseR
return (inter.numIits ; "%R
c
F2tent tests are first made to see if there is an early out. Then the proper hit(% routing is called for
the left sub tree and unless the ray misses this subtree$ the hit list rinter is formed. ,f there is a
miss$hit(% returns the alue false immediately because the ray must hit dot sub trees in order to hit
their intersection. Then the hit list rt,nter is formed.
The code is similar for the union Bool and (ifferenceBool classes. Dor
0nionBoolGGhit(%$the two hits are formed using
if((jleft&%hit(r$lft,nter%%aa(^right&%hit(r$rtinter%%%
return falseR
which proides an early out only if both hit lists are empty. Dor
differenceBoolGGhit(%$we use the code
if((jlefti;hit(r$lft,nter%% return falseR
if(jrighti;hit(r$rt,nter%%
b
inter5lft,nterR
return trueR
c
which gies an early out if the ray misses the left sub tree$ since it must then miss the
whole object.
<ui*(in+ an( usin+ E-tents for ;SC ob.e)t
The creation of projection$ sphere and bo2 e2tend for C'A object. (uring a preprocessing step$ the
true for the C'A object is scanned and e2tents are built for each node and stored within the node itself.
(uring ray tracing$ the ray can be tested against each e2tent encounter$ with the potential benefit of an
early out in the intersection process if it becomes clear that the ray cannot hit the object.
0. E-p*ain about t'e ref*e)tion of *i+'t an( transparen)". !2o 2#1:> Ma" 2#12%
1. E-p*ain about piano )ures ! Ma" 2#12%
A fractal space filling cure that can fill a plane een though it is a line of infinite length. /ddly
enough$ it has an integer fractal dimension of !.
Strin+ pro(u)tions an( peano )ures
(rawing of peano cures can be performed by the reading the string and interpreting each character as
command to perform some operation. Consider the commands to instruct a turtle to moe either forward or
bac*ward. S
H means forwar(!1>1%
Ao forward isibly distances # in the current direction
SA means turn!A%
Turn right through angle A degree
S4S means turn!4A% Turn left through angle A degree
Dor e2ample a simple string [D&D66\ with a angle e)uals >"o means moe forwar($ turn *eft b" 1#o
$moe forwar($ turn ri+'t 1#o$turn ri+'t b" 1#o.'tring production rules which are embaded in a
routine pro(u)estrin+!% are used to process the string. The rule for the Mo)' cure is
ZD k\D&D66D&D\
-IF1F [k\ means that each [D\ is replaced by [D&D66D&D\
There are two stages of the string production process. ,n the first stage$ an initial string called the
atom$ in case [D\$ \produces\ the first generating string '#5\D&D66D&D\. '# then is input into the
same process$ and it produces the second generating string.
'!5'#&'#66'#&'#
By substuting
'#5\D&D66D&D\$ then
'!5\D&D66D&D&D&D66D&D&D&D66D&D&D&D66D&D\
,n the turtle interprets '! then it draws the second generation Xoch cure X!.
Strin+ pro(u)tion app*ie( twi)e to t'e atom THU
D&D66D&D
D&D66D&D&D&D66D&D&D&D66D&D&D&D66D&D
/ne way to draw one of these cures is to hae each call to pro(u)eStrin+!%$ read a string from an
input file and ultimately write the [produced\ string to an output file. The output file of each
Pro(u)eStrin+!% becomes the input file to the ne2t stage.
Pro(u)in+ Strin+s Re)ursie*" an( Drawin+ in a pro+ram
,nstead of storing the generated string output to an output file and giing it to the Pro(u)eStrin+!%
method$ we can generate using recursie method.
Poid produce'tring(char ast$ int order%
b
Dor(RstRst66%
'witch(ast%
b case6GC(& 5 angleRbrea*R 88right turn
case&GC(6 5 angleRbrea*R 88 left turn
case ZDGif(order;"%
.roduce'tring (Dstr$ order&#%R
Flse forward(length$ ,%R brea*R
c
c
The function Pro(u)eStrin+!% scans an input string character by character. ,f the character is Z6 or
Z&[the turtle turns accordingly. ,f it is ZD Pro(u)eStrin+!% calls itself with the corresponding string
but at the ne2t lower alue of order.
A**owin+ bran)'in+
,f the turtle wants to continue from the point where it left off at some earlier point of drawing$s)uare
brac*ets can be used.
ZMZ G saeTurtle(% k store the current state of the turtle.
ZN G restoreTurtle(% k set the turtle consists of the alues of the current position(C.% and current
direction(C(%G
'tate of the turtle 5 bC.$C(c
A coneninent method for storing recent turtle states is on to a stac*. Dor e2ample
(#.3$ =.!!%$ 9= &&&&&& top of stac*
(".B$ &!.B%$ 3"
(?."$ 9.?%$ #7"
This code means tht the most recent state pushed onto the stac* was the current position(#.3$ =.!!% and
current direction 9=o$ and the state saed before that inoled a C.5(".B$ &!.B% and a C(53"o. the result
of encountering a ZMZ in a string is to [push\ the current turtle state$ to sae it for later use. The result
of encountering a ZN is to Zpop the top alue off the stac* and set the turtle state to the alue
Zpopped. ,t is enough to add two lines to the switch statement of .roduce'tring(%$
ZMZ G saeTurtle(%Rbrea*R kpush the current turtle state
ZN G restoreTurtle(%Rbrea*R k pop the turtlestate from the stac*.
This is useful to draw the trees.
6. E-p*ain about ran(om fra)ta*s! Ma" 2#12 %
Dractal is the term associated with randomly generated cures and surfaces that e2hibit a degree of self&
similarity. These cures are used to proide [naturalistic\ shapes for representing objects such as
coastlines$ rugged mountains$ grass and fire.
Hra)ta*i/in+ a Se+ment
The simplest random fractal is formed by recursiely roughening or fractali+ing a line segment. At each
step$ each line segment is replaced with a Tran(om e*bowU. The figure shows this process applied to the
line segment ' haing endpoints A and B. ' is replaced by the two segments from A to C and from C to B.
Dor a fractal cure$ point C is randomly chosen along the perpendicular bisector L of '. The elbow lies
randomly on one or the other side of the [parent\ segment AB.
Dractali+ing with a random elbow 'teps in the fractali+ation process
Three stages are re)uired in the fractali+ation of a segment. ,n the first stage$ the midpoint of AB is
perturbed to form point C. ,n the second stage $ each of the two segment has its midpoints perturbed to
form points ( and F. ,n the third and final stage$ the new points Dg.., are added.
To perform fra)ta*i/ation in a pro+ram
Line L passes through the midpoint @ of segment ' and is perpendicular to it. Any point C along L has the
parametric formG
C(t% 5 @ 6 (B&A% t &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&(?%
for some alues of t$ where the midpoint @5 (A6B%8!.
The distance of C from @ is ^B&A^^t^$ which is proportional to both t and the length of '. 'o to produce a
point C on the random elbow$ we let t be computed randomly. ,f t is positie$ the elbow lies to one side of
ABR if t is negatie it lies to the other side.
Dor most fractal cures$ t is modeled as a Aaussian random ariable with a +ero mean and some standard
deiation. 0sing a mean of +ero causes$ with e)ual probability$ the elbow to lie aboe or below the parent
segment.
Hra)ta*i/in+ a Line se+ment
oid fract(.oint! A$ .oint! B$ double std(e%
88 generate a fractal cure from A to B
double 2(iff 5 A.2 < B.2$ y(iff5 A.y <B.yR
.oint! CR
if(2(iff a L(iff 6 E(iff a y(iff : minLen')%
cs.lintTo(B.2$ B.y%R
else
b
std(e a5factorR 88scale std(e by factor
double t5"R
88 ma*e a gaussian ariate t lying between " and #!."
for(int i5"R ,$ #!R i66%
t65 rand(%83!?>7."R
t5 (t&>% a std(eR 88shift the mean to " and sc
C.2 5 ".= a(A.2 6B.2% < t a (B.y < A.y%R
C.y 5 ".= a(A.y 6B.y% < t a (B.2 < A.2%R
fract(A$ C$ std(e%R
fract(C$ B$ std(e%R
c
The routine fract(% generates cures that appro2imate actual fractals. The routine recursiely replaces
each segment in a random elbow with a smaller random elbow. The stopping criteria used isG -hen
the length of the segment is small enough$ the segment is drawn using cs.lineTo(%$ where cs is a
Canas object. The ariable t is made to be appro2imately Aaussian in its distribution by summing
together #! uniformly distributed random alues lying between " and #. The result has a mean alue of
> and a ariance of #. The mean alue is then shifted to " and the ariance is scaled as necessary.
The depth of recursion in fract(% is controlled by the length of the line segment.