You are on page 1of 69

INDEX

Ex.
No
Date Name of the Experiment P. No Sign
1
BRESENHAMS LINE DRAWING
ALGRI!HM
"
BRESENHAMS #IR#LE DRAWING
ALGRI!HM
$
BRESENHAMS ELLIPSE DRAWING
ALGRI!HM
%
&!P&! PRIMI!I'ES
(
!W ) DIMENSINAL
!RANS*RMA!IN
+
#MPSI!E !W ) DIMENSINAL
!RANS*RMA!IN
,
#HEN S&!HERLAND "D LINE #LIPPING
-
WINDWING ! 'IEWPR! MAPPING
.
S&!HERLAND ) HDGEMANN PL/GN
#LIPPING ALGRI!HM
10
!HREE ) DIMENSINAL
!RANS*RMA!IN
11
#MPSI!E !HREE ) DIMENSINAL
!RANS*RMA!IN
1"
GENERA!ING *RA#!AL IMAGES
E1 N2 1 BRESENHAMS LINE DRAWING ALGRI!HM
DA!E 2
Aim2
To write a C program to draw a line using Bresenhams Algorithm.

A3gorithm2
Step 12Start the program.
Step "2Input the two endpoints (x1,y1) and (x,y).
Step $2!lot the pixel "alue (x1,y1) with a spe#i$ied #olor.
Step %2Cal#ulate the "alue o$ dx and dy and $ind the starting "alue o$ de#ision parameter
as dp%&dy'dx.
Step (2Cal#ulate the "alues o$ s1 and s depending on (x1,y1) and (x,y) "alues.
Step +2I$ dp(), the next point to plot is (x,y*s) and dp%*&dy.
Step ,2+therwise the next point to plot is (x*s1,y*s) and
dp%dp*&dx'&dy.
Step -2,epeat steps - and . dx times.
Step .2Stop the program.

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
PRGRAM 2
/in#lude(stdio.h0
/in#lude(math.h0
/in#lude(#onio.h0
/in#lude(graphi#s.h0
"oid main()
1
int x1,x,y1,y2
int gd%34T4CT,gm2
"oid line5res(int,int,int,int)2
print$(64nter the two end points76)2
s#an$(68d8d8d8d6,9x1,9x,9y1,9y)2
initgraph(9gd,9gm,66)2
#learde"i#e()2
line5res(x1,y1,x,y)2
get#h()2
line(x1,y1,x,y)2
get#h()2
#losegraph()2
:
"oid line5res(int x1,int y1,int x,int y)
1
int dx%a5s(x1'x),dy%a5s(y1'y)2
int p,x,y,i,xend,yend2
i$(dx;%))
1
p%&dy'dx2
i$(x10x)
1
x%x2
y%y2
xend%x12
:
else
1
x%x12
y%y12
xend%x2
:
putpixel(x,y,)2
$or(i%x2i(xend2i**)
1
x*%12
i$(p())
p*%&dy2
else
p*%&(dy'dx)2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
:
putpixel(x,y,)2
:
else
1
p%&dx'dy2
i$(y10y)
1
x%x2
y%y2
yend%y2
:
putpixel(x,y,)2
$or(i%y2i(yend2i**)
1
y*%12
i$(p())
p*%&dx2
else
1
x*%12
p*%&(dx'dy)2
:
putpixel(x,y,)2
:
:
:
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
&!P&! 2
Bresenham line drawing algorithm
4nter the #o'ordinates
1-) 1)) -) <))
RES&L!2
Thus the a5o"e program has 5een exe#uted and output is "eri$ied.
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
E1 N2 " BRESENHAMS #IR#LE DRAWING ALGRI!HM
DA!E2
Aim 2
To write a C program to draw a Cir#le using Bresenhams Algorithm.
A3gorithm2
Step 12Start the program.
Step "2Input radius r and the midpoint o$ the #ir#le (x,y) and o5tain the $irst point on the
#ir#um$eren#e $or the #ir#le as (),r).
Step $2Cal#ulate the initial "alue o$ the de#ision parameter as p%1'r.
Step %2At ea#h position #he#= the $ollowing #onditions.
a) I$ p() then x%x*1 and p*%&x*1
5) 4lse y%y'1 and p*%&(x'y)*1.
Step (23etermine symmetry points at the other se"en o#tants.
Step +2>o"e ea#h #al#ulated pixel position (x,y) onto the #ir#ular path #entered on (x#,y#)
and plot the #oordinate "alue as x%x*x# and y%y*y#.
Step ,2,epeat step < until x(y.
Step -2Stop the program.
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
PRGRAM 2
/in#lude(stdio.h0
/in#lude(#onio.h0
/in#lude(graphi#s.h0
"oid main()
1
int gd%34T4CT,gm2
int x,y,r2
"oid #ir(int,int,int)2
print$(64nter the >id points and ,adious76)2
s#an$(68d8d8d6,9x,9y,9r)2
initgraph(9gd,9gm,66)2
#ir(x,y,r)2
get#h()2
#losegraph()2
:
"oid #ir(int x1,int y1,int r)
1
int x%),y%r,p%1'r2
"oid #liplot(int,int,int,int)2
#liplot(x1,y1,x,y)2
while(x(y)
1
x**2
i$(p())
p*%&x*12
else
1
y''2
p*%&(x'y)*12
:
#liplot(x1,y1,x,y)2
:
:
"oid #liplot(int x#tr,int y#tr,int x,int y)
1
putpixel(x#tr *x,y#tr *y,1)2
putpixel(x#tr 'x,y#tr *y,1)2
putpixel(x#tr *x,y#tr 'y,1)2
putpixel(x#tr 'x,y#tr 'y,1)2
putpixel(x#tr *y,y#tr *x,1)2
putpixel(x#tr 'y,y#tr *x,1)2
putpixel(x#tr *y,y#tr 'x,1)2
putpixel(x#tr 'y,y#tr 'x,1)2
get#h()2
:

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING

OUTPUT:
Enter the Mid points and Radious:100 100 50
RES&L!2
Thus the above progra has been e!e"uted and output is veri#ed$

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
E1 N2 $ BRESENHAMS ELLIPSE DRAWING ALGRI!HM
DA!E2


Aim 2
To write a C program to draw a 4llipse using Bresenhams Algorithm

A3gorithm2
Step 12Start the program.
Step "2Input r
x
4 r
y
and the #enter o$ the ellipse (x
5
46
5
)and o5tain the $irst point on the ellipse
#entered on the origin as (x
)
,y
)
) % (),r
y
).
Step $2Cal#ulate the initial "alue o$ the de#ision parameter as P1
0
7 r
6
"
) r
x
"
r
6
8 9r
x
"
Step %2At ea#h position k x in region 1, starting at =%),per$orm the $ollowing test. I$ p1
=
( )
the next pt along the ellipse #entered on (),)) is :x
;81
46
;
< and p1
;81
7 p1
;
8 "r
6
"
x;81 8 r
6
"
Step (2+therwise the next point along the ellipse is :x
;
8146
;
=1< and
p1
;81
7 p1
;
8"r
6
"
x
;81
)"r
x
"
6
;81
8r
6
"
with
"r
6
"
x
;81
7 "r
6
"
x
;
8"r
6
"
4 "r
x
"
6
;81
7 "r
x
"
6
;
) "r
x
"
and #ontinue until "r
6
"
x >"r
x
"
6.
Step +2Cal#ulate the initial position o$ the de#ision parameter in region as
P"0 7 r6"
"
8 r
6
"
: 6
0 ) 1
<
"
= r
x
"
r
6
"
where (x
)
,y
)
) is the last position
Step ,2At ea#h y
=
position in region , starting at =%),per$orm the $ollowing test , i$ p
=
0 )
the next point along the ellipse #entered on (),)) is : x
;
4 6
;81
< and
p"
;81
7 p"
;
) "r
x
"
6
;81
8 r
6
"
.
Step -2+therwise the next point along the ellipse is ( x
=
* 1 ,y
=
'1) and
P"
;81
7 p"
;
) "r
6
"
x
;81
) "r
x
"
6
;81
8 r
x
"
.
Step .2?sing the same in#remental "alues $or x and y as in region 1 #ontinue until y%).
Step 102@or 5oth regions determine symmetry points along the other three Auadrants.
Step 112>o"e ea#h #al#ulated pixel position (x,y) on to the ellipti#al path #entered on
(x
#
, y
#
) and plot the #o'ordinates "alues x % x * x
# ,
y % y * y
#
.
Step 1"23isplay the output points.
Step 1$2Stop the program.

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
PRGRAM2
/in#lude(stdio.h0
/in#lude(#onio.h0
/in#lude(math.h0
/in#lude(graphi#s.h0
main()
1
int gd%34T4CT,gm2
int x#enter,y#enter,rx,ry2
int p,x,y,px,py,rx1,ry1,rx,ry2
initgraph(9gd,9gm,6#7BBt#BB5gi6)2
print$(64nter The ,adius Calue7Bn6)2
s#an$(68d8d6,9rx,9ry)2
print$(64nter The x#enter and y#enter Calues7Bn6)2
s#an$(68d8d6,9x#enter,9y#enter)2
ry1%ry&ry2
rx1%rx&rx2
ry%&ry12
rx%&rx12
x%)2
y%ry2
plotpoints(x#enter,y#enter,x,y)2
p%(ry1'rx1&ry*().-&rx1))2
px%)2
py%rx&y2
while(px(py)
1
x%x*12
px%px*ry2
i$(p0%))
y%y'12
py%py'rx2
i$(p())
p%p*ry1*px2
else
p%p*ry1*px'py2
plotpoints(x#enter,y#enter,x,y)2
p%(ry1&(x*).-)&(x*).-)*rx1&(y'1)&(y'1)'rx1&ry1)2
while(y0))
1
y%y'12
py%py'rx2
i$(p(%))
1
x%x*12
px%px*ry2
:
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
i$(p0))
p%p*rx1'py2
else
p%p*rx1'py*px2
plotpoints(x#enter,y#enter,x,y)2
::
get#h()2
return())2
:
int plotpoints(int x#enter,int y#enter,int x,int y)
1
putpixel(x#enter*x,y#enter*y,.)2
putpixel(x#enter'x,y#enter*y,.)2
putpixel(x#enter*x,y#enter'y,.)2
putpixel(x#enter'x,y#enter'y,.)2

:

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
&!P&!2
4nter the ,adius Calue 7 1) <)
4nter the D Center and E Center7 <)) 1-)
RES&L!2
Thus the a5o"e program has 5een exe#uted and output is "eri$ied.

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
E1 N2 % &!P&! PRIMI!I'ES
DA!E2


Aim 2
To write a C program to draw the "arious attri5utes o$ line, #ir#le and ellipse.

A3gorithm2
Step 12Start the program.
Step "2InitialiFe the "aria5les.
Step $2Call the initgraph() $un#tion
Step %2Set #olor $or the output primiti"es.
Step (2?sing +uttextxy() display the #hosen parti#ular primiti"es.
Step +2In#lude the "arious attri5utes o$ line, #ir#le and ellipse.
Step ,2Close the graph and run the program.
Step -2Stop the program

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
PRGRAM2
/in#lude(stdio.h0
/in#lude(#onio.h0
/in#lude(graphi#s.h0
/in#lude(string.h0
"oid main()
1
#har #h%GyG2
int gd%34T4CT,gm,x1,y1,x,y,rad,sa,ea,xrad,yrad,i2
initgraph(9gd,9gm,66)2
while(#h%%GyG)
1
#learde"i#e()2
set5=#olor(H)2
outtextxy(1)),1<),6Choose @rom The @ollowing 6)2
outtextxy(1)),1-),61. Iine6)2
outtextxy(1)),1J),6.Cir#le6)2
outtextxy(1)),1H),6<.Box6)2
outtextxy(1)),1),6K.Ar#6)2
outtextxy(1)),<),6-.4llipse6)2
outtextxy(1)),-),6..,e#tangle6)2
outtextxy(1)),J),6J.4xit6)2
#h%get#h()2
#learde"i#e()2
swit#h(#h)
1
#ase G1G7
line(1)),)),<)),K)))2
5rea=2
#ase GG7
#ir#le()),)),1)))2
5rea=2
#ase G<G7
set$illstyle(-,K)2
5ar(1)),<)),)),1)))2
5rea=2
#ase GKG7
set$illstyle(-,K)2
ar#()),)),1)),<)),1)))2
5rea=2
#ase G-G7
set$illstyle(-,K)2
$illellipse(1)),1)),-),1)))2
5rea=2
#ase G.G7
settextstyle(34@A?ITL@+MT,),)2
outtextxy(1),1K),6A>SC+II4N46)2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
line(1)),1)),1)),<)))2
line(<)),<)),1)),<)))2
line(1)),1)),<)),1)))2
line(<)),1)),<)),<)))2
5rea=2
#ase GJG7
#losegraph()2
return2
:
#h%GyG2
get#h()2
:
:
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
&!P&!2
Choose $rom the $ollowing
1.Iine
. Cir#le
<.Box
K.Ar#
-.4llipse
..,e#tangle
J.4xit


1. LINE ". #IR#LE
%. AR# (. ELLIPSE
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
+. RE#!ANGLE
RES&L!2
Thus the a5o"e program has 5een exe#uted and output is "eri$ied.
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
E1 N2 ( !W ) DIMENSINAL !RANS*RMA!IN
DA!E2

Aim 2
To write a C program to per$orm 3 trans$ormations su#h as translation, rotation, s#aling,
re$le#tion and shearing.

A3gorithm2
Step 12Start the program.
Step "2Input the o5Oe#t #oordinates
Step $2@or Translation
a) 4nter the translation $a#tors tx and ty.
5) >o"e the original #oordinate position (x,y) to a new position (x1,y1).ie. x%x*x1,
y%y*y1.
#) 3isplay the o5Oe#t a$ter translation
Step %2@or ,otation
a) 4nter the radian $or rotation angle P.
5) ,otate a point at position (x,y) through an angle P a5out the origin
x1%x#os P ' ysin P , y1%y#os P * xsin P.
#) 3isplay the o5Oe#t a$ter rotation
Step (2@or S#aling
a) Input the s#aled $a#tors sx and sy.
5) The trans$ormed #oordinates (x1,y1) , x1%x.sx and y1%y.sy.
#) 3isplay the o5Oe#t a$ter s#aling
Step +2,e$le#tion #an 5e per$ormed a5out x axis and y axis.
a) ,e$le#tion a5out x axis 7 The trans$ormed #oordinates are x1%a and y1%'y.
5) ,e$le#tion a5out y axis 7 The trans$ormed #oordinates are x1%x and y1%y.
#) 3isplay the o5Oe#t a$ter re$le#tion
Step ,2@or Shearing
a) Input the shearing $a#tors shx and shy.
5) Shearing related to x axis 7 Trans$orm #oordinates x1%x*shx&y and y1%y.
#) Shearing related to y axis 7 Trans$orm #oordinatesx1%x and y1%y*shy&x.
d) Input the xre$ and yre$ "alues.
e) D axis shear related to the re$eren#e line y'yre$ is x1%x*shx(y'yre$) and y1%y.
$) E axis shear related to the re$eren#e line x%xre$ is x1%x
g) 3isplay the o5Oe#t a$ter shearing
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
Step -2Stop the !rogram.

PRGRAM2
/in#lude(stdio.h0
/in#lude(#onio.h0
/in#lude(graphi#s.h0
/in#lude(dos.h0
/in#lude(math.h0
/in#lude(stdli5.h0
"oid menu()2
"oid input()2
"oid output()2
"oid translation()2
"oid rotation()2
"oid s#aling()2
"oid shearing()2
"oid re$le#tion()2
int aQ1)RQR,i,x,option,temp,angle,tx,ty,$x,$y,sh,=,n,axis,y2
$loat sx,sy2

"oid menu()
1
print$(6menuBn6)2
print$(61.TranslationBn6)2
print$(6.rotationBn6)2
print$(6<.s#alingBn6)2
print$(6K.shearingBn6)2
print$(6-.re$le#tionBn6)2
print$(6..exitBn6)2
print$(6enter the #hoi#e76)2
s#an$(68d6,9option)2
swit#h(option)
1
#ase 17
input()2
translation()2
5rea=2
#ase 7
input()2
rotation()2
5rea=2
#ase <7
input()2
s#aling()2
5rea=2

#ase K 7
input()2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
shearing()2
5rea=2
#ase -7
input()2
re$le#tion()2
5rea=2
#ase .7
exit())2
5rea=2
:
:
"oid input()
1
print$(6enter the num5er o$ "erti#es76 )2
s#an$(68d6,9n)2
$or(i%)2i(n2i**)
1
print$(6enter the #oordinates76)2
s#an$(68d8d8d8d6,9aQiRQ)R,9aQiRQ1R,9aQi*1RQ)R,9aQi*1RQ1R)2
:
:

"oid output()
1
#learde"i#e()2
$or(i%)2i(n2i**)
1
line(aQiRQ)R,aQiRQ1R,aQi*1RQ)R,aQi*1RQ1R)2
:
:
"oid translation()
1
output()2
print$(6enter the tran$ormation "ertex tx,ty7Bn6)2
s#an$(68d8d6,9tx,9ty)2
$or(i%)2i(%n2i**)
1
aQiRQ)R%aQiRQ)R*tx2
aQiRQ1R%aQiRQ1R*ty2
:
output()2
delay(1))2
menu()2
:

"oid rotation()
1
output()2
print$(6enter the rotating angle76)2
s#an$(68d6,9y)2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
print$(6enter the pi"ot point76)2
s#an$(68d8d6,9$x,9$y)2
=%(y&<.1K)S1T)2
$or(i%)2i(%n2i**)
1
aQiRQ)R%$x*(aQiRQ)R'$x)&#os(=)'(aQiRQ1R'$y)&sin(=)2
aQiRQ1R%$y*(aQiRQ)R'$x)&sin(=)'(aQiRQ1R'$y)&#os(=)2
:
output()2
delay(1))2
menu()2
:
"oid s#aling()
1
output()2
print$(6enter the s#aling $a#torBn6)2
s#an$(68$8$6,9sx,9sy)2
print$(6enter the $ixed point76)2
s#an$(68d8d6,9$x,9$y)2
$or(i%)2i(%n2i**)
1
aQiRQ)R%aQiRQ)R&sx*$y&(1'sx)2
aQiRQ1R%aQiRQ1R&sy*$y&(1'sy)2
:
output()2
delay(1))2
menu()2
:
"oid shearing()
1
output()2
print$(6enter the shear "alue76)2
s#an$(68d6,9sh)2
print$(6enter the $ixed point76)2
s#an$(68d8d6,9$x,9$y)2
print$(6enter the axis $or shearing i$ x'axis then 1 i$ y'axis the )76)2
s#an$(68d6,9axis)2
$or(i%)2i(%n2i**)
1
i$(axis%%1)
1
aQiRQ)R%aQiRQ)R*sh&(aQiRQ1R'$y)2
:
else
1
aQiRQ1R%aQiRQ1R*sh&(aQiRQ)R'$x)2
:
:
output()2
delay(1))2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
menu()2
:
"oid re$le#tion()
1
output()2
$or(i%)2i(%n2i**)
1
temp%aQiRQ)R2
aQiRQ)R%aQiRQ1R2
aQiRQ1R%temp2
:
output()2
delay(1))2
menu()2
:
"oid main()
1
int gd%34T4CT,gm2
initgraph(9gd,9gm,6#7BBt#BB5gi6)2
menu()2
get#h()2
:

&!P&!2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
Men?
Translation
1. ,otation
. ,otation
<. S#aling
K. Shearing
-. ,e$le#tion
.. 4xit

4nter the #hoi#e 7 1
4nter the num5er o$ Certi#es7 <
4nter the #oordinates 7 <) 1-) 1) ))
4nter the #oordinates 7 1) )) .) ))
4nter the #oordinates 7 .) )) <) 1-)

4nter the translation "e#tor Tx, Ty 7 H) .)

R!A!IN
4nter the #hoi#e 7
4nter the num5er o$ Certi#es7 <
4nter the #oordinates 7 <) 1-) 1) ))
4nter the #oordinates 7 1) )) .) ))
4nter the #oordinates 7 .) )) <) 1-)
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING

4nter the ,otating Angle 7 H)
4nter the !i"ot !oint 7 1)) ))

S#ALING
4nter the #hoi#e 7 <
4nter the num5er o$ Certi#es7 <
4nter the #oordinates 7 <) 1-) 1) ))
4nter the #oordinates 7 1) )) .) ))
4nter the #oordinates 7 .) )) <) 1-)

4nter the s#aling @a#tor 7 ).< ).K
4nter the @ixed !oint 7 1)) ))
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING

SHEARING
4nter the #hoi#e 7 K
4nter the num5er o$ Certi#es7 <
4nter the #oordinates 7 <) 1-) 1) ))
4nter the #oordinates 7 1) )) .) ))
4nter the #oordinates 7 .) )) <) 1-)
4nter the shear Calue 7 -
4nter the $ixed point 7 -) 1))
4nter the Axis $or shearing i$ x'axis then 1
i$ y'axis then )


VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
RE*LE#!IN
4nter the #hoi#e 7 -
4nter the num5er o$ Certi#es7 <
4nter the #oordinates 7 <) 1-) 1) ))
4nter the #oordinates 7 1) )) .) ))
4nter the #oordinates 7 .) )) <) 1-)



RES&L!2
Thus the a5o"e program has 5een exe#uted and output is "eri$ied.
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
E1 N2 + #MPSI!E !W ) DIMENSINAL !RANS*RMA!IN
DA!E2
Aim 2
To write a C** program to per$orm #omposite 3 trans$ormations su#h as translation,
rotation, s#aling, re$le#tion and shearing.

A3gorithm2
Step 12Start the program.
Step "2Input the o5Oe#t #oordinates.
Step $2Translation
a) 4nter the translation $a#tors tx and ty.
5) >o"e the original #oordinate position (x,y) to a new position
(x1,y1).ie. x%x*x1, y%y*y1.
Step %2,otation
a) 4nter the radian $or rotation angle P.
5) ,otate a point at position (x,y) through an angle P a5out the origin x1%x#os P '
ysinP , y1%y#osP * xsinP.
Step (2S#aling
a) Input the s#aled $a#tors sx and sy.
5) The trans$ormed #oordinates (x1,y1) , x1%x.sx and y1%y.sy.
Step +2,e$le#tion
a) ,e$le#tion a5out x axis 7 The trans$ormed #oordinates are x1%a and y1%'y.
Step ,2,e$le#tion a5out y axis 7 The trans$ormed #oordinates are x1%x and y1%y.
Step -2Shearing
a) Input the shearing $a#tors shx and shy.
5) Shearing related to x axis 7 Trans$orm #oordinates x1%x*shx&y and y1%y.
#) Shearing related to y axis 7 Trans$orm #oordinates x1%x and y1%y*shy&x.
d) Input the xre$ and yre$ "alues.
e) D axis shear related to the re$eren#e line y'yre$ is x1%x*shx(y'yre$) and y1%y.
$) E axis shear related to the re$eren#e line x%xre$ is x1%x and y1%y*shy(x'xre$)
Step .2@inally display the trans$ormed o5Oe#t a$ter the su##essi"e trans$ormations.
Step 102Stop the !rogram.
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING

PROGRAM:
/in#lude(iostream.h0
/in#lude(#onio.h0
/in#lude(math.h0
/in#lude(graphi#s.h0
/in#lude(stdli5.h0
"oid main()
1
int gd,gm,n,i,xaQ1)R,yaQ1)R,op,tx,ty,xa1Q1)R,ya1Q1)R,theta,x$,y$,rx,ry,
sx,sy,shx,shy,xre$,yre$2
#har d2
gd%34T4CT2
initgraph(9gd,9gm,66)2
#out((6enter the no o$ points62
#in00n2
$or(i%)2i(n2i**)
1
#out((6enter the #oordinates6((i*12
#in00xaQiR00yaQiR2
:
do
1
#out((6menu62
#out((6Bn1.translationBn.rotationBn<.s#alingBnK.shearingBn-.re$le#tionBn..exit62
#in00op2
swit#h(op)
1
#ase 17
#out((6enter the translation "e#tor62
#in00tx00ty2
$or(i%)2i(n2i**)
1
xa1QiR%xaQiR*tx2
ya1QiR%yaQiR*ty2
:
#learde"i#e()2
#out((65e$ore translation62
$or(i%)2i(n2i**)
1
line(xaQiR,yaQiR,xaQ(i*1)8nR,yaQ(i*1)8nR)2
:
#out((6a$ter translation62
$or(i%)2i(n2i**)
1
line(xa1QiR,ya1QiR,xa1Q(i*1)8nR,ya1Q(i*1)8nR)2
:
get#h()2
#learde"i#e()2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
5rea=2
#ase 7
#out((6enter the rotation angle62
#in00theta2
theta%(theta&<.1K)S1T)2
#out((6enter the re$eren#e points62
#in00x$00y$2
$or(i%)2i(n2i**)
1
xa1QiR%x$*(xaQiR'x$)&#os(theta)'(yaQiR'y$)&sin(theta)2
ya1QiR%y$*(xaQiR'x$)&sin(theta)'(yaQiR'y$)&#os(theta)2
:
#learde"i#e()2
#out((65e$ore rotation62
$or(i%)2i(n2i**)
1
line(xaQiR,yaQiR,xaQ(i*1)8nR,yaQ(i*1)8nR)2
:
#out((6a$ter rotation62
$or(i%)2i(n2i**)
1
line(xa1QiR,ya1QiR,xa1Q(i*1)8nR,ya1Q(i*1)8nR)2
:
get#h()2
#learde"i#e()2
5rea=2
#ase <7
#out((6enter the s#aling $a#tor62
#in00sx00sy2
#out((6enter the re$eren#e point62
#in00rx00ry2
$or(i%)2i(n2i**)
1
xa1QiR%xaQiR&sx*rx&(1'sx)2
ya1QiR%yaQiR&sy*ry&(1'sy)2
:
#learde"i#e()2
#out((65e$ore s#aling62
$or(i%)2i(n2i**)
1
line(xaQiR,yaQiR,xaQ(i*1)8nR,yaQ(i*1)8nR)2
:
#out((6a$ter s#aling62
$or(i%)2i(n2i**)
1
line(xa1QiR,ya1QiR,xa1Q(i*1)8nR,ya1Q(i*1)8nR)2
:
get#h()2
#learde"i#e()2
5rea=2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
#ase K7
#out((6enter the shear "alue62
#in00shx00shy2
#out((6enter the re$eren#e point62
#in00xre$00yre$2
#out((6enter the shear dire#tion x or y62
#in00d2
i$(d%%GxG)
1
$or(i%)2i(n2i**)
1
xa1QiR%xaQiR*shx&(yaQiR'yre$)2
ya1QiR%yaQiR2
:
:
#learde"i#e()2
#out((65e$ore shearing62
$or(i%)2i(n2i**)
1
line(xaQiR,yaQiR,xaQ(i*1)8nR,yaQ(i*1)8nR)2
:
#out((6a$ter shearing62
$or(i%)2i(n2i**)
1
line(xa1QiR,ya1QiR,xa1Q(i*1)8nR,ya1Q(i*1)8nR)2
:
get#h()2
#learde"i#e()2
5rea=2
#ase -7
#out((65e$ore re$le#tion62
$or(i%)2i(n2i**)
1
line(xaQiR,yaQiR,xaQ(i*1)8nR,yaQ(i*1)8nR)2
:
#out((6a$ter re$le#tion62
$or(i%)2i(n2i**)
1
line(yaQiR,xaQiR,yaQ(i*1)8nR,xaQ(i*1)8nR)2
:
get#h()2
#learde"i#e()2
5rea=2
#ase .7
exit())2
5rea=2
:
:while(op;%.)2
:

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
&!P&! 2

enter the no o$ points7 <
enter the #oordinates17 -) 1-)
enter the #oordinates7 -) -)
enter the #oordinates <7 J- 1-)

menu
1. translation
. rotation
<. s#aling
K.shearing
-.re$le#tion
..exit

1

enter the translation "e#tor7 <) K)

B4@+,4 A@T4,
menu
1. translation
. rotation
<. s#aling
K.shearing
-.re$le#tion
..exit

enter the rotation angle7 .)


enter the re$eren#e points7 <) K)
B4@+,4 A@T4,
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
menu
1. translation
. rotation
<. s#aling
K.shearing
-.re$le#tion
..exit

<
4nter the s#aling $a#tor7 < K
4nter the re$eren#e points7 <) K)
B4@+,4 A@T4,

menu
1. translation
. rotation
<. s#aling
K.shearing
-.re$le#tion
..exit

K

4nter the shear "alue7 < K
4nter the re$eren#e point7 ) <)
4nter the shear dire#tion x or y7 D
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
B4@+,4 A@T4,
menu
1. translation
. rotation
<. s#aling
K.shearing
-.re$le#tion
..exit

-
B4@+,4 A@T4,

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING

RES&L!2
Thus the a5o"e program has 5een exe#uted and output is "eri$ied.

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
E1 N2 , #HEN S&!HERLAND "D LINE #LIPPING
DA!E2

Aim 2
To write a C program to #lip a line using Cohen'Sutherland #lipping algorithm.

A3gorithm2
Step 12Start the program.
Step "24nter the line end points and the window #oordinates.
Step $24"ery line end point is assigned a #ode that identi$ied the lo#ation o$ the point relati"e
to the 5oundaries o$ the #lipping re#tangle.
Step %2Che#= whether the line lies inside the window then it is entirely drawn.
Step (2Che#= whether the line lies outside the window then it is entirely #lipped.
Step +2+therwise #he#= whether the line interse#ts the window7
a) Cal#ulate di$$eren#es 5etween end points and #lip 5oundaries.
5) 3etermine the interse#tion point and how mu#h o$ the line is to 5e dis#arded.
Step ,23isplay the +utput.
Step -2Stop the program.



VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
PRGRAM2
/in#lude(stdio.h0
/in#lude(math.h0
/in#lude(graphi#s.h0
/in#lude(#onio.h0
$loat #xl, #xr,#yt,#y52
#ode($loat,$loat)2
"oid #lip($loat,$loat,$loat,$loat)2
"oid re#t($loat,$loat,$loat,$loat)2
"oid main()
1
$loat x1,y1,x,y2
int g%),d2
initgraph(9g,9d,6#7BBt#BB5in6)2
settextstyle(1,),1)2
outtextxy(K),1-,6B4@+,4 CII!!IMN6)2
print$(6BnBnBn please enter the le$t,5ottom,right,top,o$ #lip window6)2
s#an$(68$8$8$8$6,9#xl,9#yt,9#xr,9#yt)2
re#t(#xl,#y5,#xr,#yt)2
get#h()2
print$(6Bn please enter the line(x1,y1,x,y)76)2
s#an$(68$8$8$8$6,9x1,9y1,9x,9y)2
line(x1,y1,x,y)2
get#h()2
#learde"i#e()2
settextstyle(1,),1)2
outtextxy(K),1-,6a$ter #lipping6)2
#lip(x1,y1,x,y)2
get#h()2
#losegraph()2
:
"oid #lip($loat x1,$loat y1,$loat x,$loat y)
1
int #,#1,#2
$loat x,y2
#1%#ode(x1,y1)2
#%#ode(x,y)2
get#h()2
while((#1;%))UU(#;%)))
1
i$((#19#);%))
goto out2
#%#12
i$(#%%))
#%#2
i$((#91)%%1)
1
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
y%y1*(y'y1)&(#xl'x1)S(x'x1)2
x%#xl2
:
else
i$((#9)%%)
1
y%y1*(y'y1)&(#xl'x1)S(x'x1)2
x%#xr2
:
else
i$((#9T)%%T)
1
x%x1*(x'x1)&(#y5'y1)S(y'y1)2
y%#y52
:
else
i$((#9K)%%K)
1
x%x1*(x'x1)&(#yt'y1)S(y'y1)2
y%#yt2
:
i$(#%%#1)
1
x1%x2
y1%y2
#1%#ode(x,y)2
:

else
1
x%x2
y%y2
#%#ode(x,y)2
:
:
out 7 re#t(#xl,#y5,#xr,#yt)2
line(x1,y1,x,y)2
:
#ode($loat x,$loat y)
1
int #%)2
i$(x(#xl)
#%12
else
i$(x0#xr)
#%2
i$(y(#y5)
#%#UT2
else
i$(y0#yt)
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
#%#UK2
return #2
:
"oid re#t($loat xl,$loat y5,$loat xr,$loat yt)
1
line(xl,y5,xr,y5)2
line(xr,y5,xr,yt)2
line(xr,yt,xl,yt)2
line(xl,yt,xl,y5)2
:
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
&!P&!2
4nter the le$t, 5ottom, right ,top o$ #lip window
))
))
K))
K))

enter the line #oordinates
-)
<))
K))
K-)
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
RES&L!2
Thus the a5o"e program has 5een exe#uted and output is "eri$ied.
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
E1 N2 - WINDWING ! 'IEWPR! MAPPING
DA!E2

Aim 2
To write a C program to #lip a Vindow to Ciewport >apping.


A3gorithm2
Step 12Start the program.
Step "2Net the maximum and minimum #o'ordinates o$ the Vindow
Step $2Net the maximum and minimum #o'ordinates o$ the Ciew!ort
Step %2Net the #o'ordinates o$ a point 5y $itting window in "iewport.
Step (23isplay the output.
Step +2Stop the program.


VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
PRGRAM2
/in#lude(stdio.h0
/in#lude(#onio.h0
/in#lude(graphi#s.h0
/in#lude(math.h0
main()
1
$loat sx,sy2
int w1,w,w<,wK,x1,x,x<,xK,y1,y,y<,yK,"1,","<,"K2
int gd%34T4CT,gm2
initgraph(9gd,9gm,6#7BBt#BB5gi6)2
print$(64nter The Coordinate x1,y1,x,y,x<,y<Bn6)2
s#an$(68d8d8d8d8d8d6,9x1,9y1,9x,9y,9x<,9y<)2
#learde"i#e()2
w1%-2
w%-2
w<%.<-2
wK%K.-2
re#tangle(w1,w,w<,wK)2
line(x1,y1,x,y)2
line(x,y,x<,y<)2
line(x<,y<,x1,y1)2
get#h()2
"1%K-2
"%J-2
"<%--)2
"K%-)2
sx%($loat)("<'"1)S(w<'w1)2
sy%($loat)("K'")S(wK'w)2
re#tangle("1,","<,"K)2
x1%"1*$loor((($loat)(x1'w1)&sx)*.-)2
x%"1*$loor((($loat)(x'w1)&sx)*.-)2
x<%"1*$loor((($loat)(x<'w1)&sx)*.-)2
y1%"*$loor((($loat)(y1'w)&sy)*.-)2
y%"*$loor((($loat)(y'w)&sy)*.-)2
y<%"*$loor((($loat)(y<'w)&sy)*.-)2
line(x1,y1,x,y)2
line(x,y,x<,y<)2
line(x<,y<,x1,y1)2
get#h()2
return )2
:

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
+?T!?T7

4nter The Coordinate x1,y1,x,y,x<,y<
1))
))
<))
K))
-))
<-)

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
RES&L!2
Thus the a5o"e program has 5een exe#uted and output is "eri$ied.
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
E1 N2 . S&!HERLAND ) HDGEMANN PL/GN #LIPPING ALGRI!HM
DA!E2

Aim 2
To write a C program to implement S&!HERLAND ) HDGEMANN polygon #lipping
algorithm.


A3gorithm2
Step 12Start the program.
Step "2Input Coordinates o$ all "erti#es o$ the polygon
Step $2Input #oordinates o$ the #lipping window
Step %2Consider the le$t edge o$ the window
Step (2Compare the "erti#es o$ ea#h edge o$ the polygon , ndi"idually with the #lipping
plane
Step +2Sa"e the resulting interse#tions and "erti#es in the new list o$ "erti#es a##ording to
$our possi5le relationships 5etween the edge and the #lipping 5oundary dis#ussed
earlier
Step ,2,epeat the steps K and - $or remaining edges o$ the #lipping window. 4a#h time the
resultant list o$ "erti#es is su##essi"ely passed to pro#ess the next edge o$ the #lipping
window
Step -2Stop the !rogram.

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
PRGRAM2
/in#lude (stdio.h0
/in#lude (graphi#s.h0
/in#lude (#onio.h0
/in#lude (math.h0
/in#lude (pro#ess.h0
/de$ine T,?4 1
/de$ine @AIS4 )
typede$ unsigned int out#ode2
out#ode Comp+utCode($loat x,$loat y)2
enum1
T+! % )x1,
B+TT+> % )x,
,INWT % )xK,
I4@T % )xT
:2
$loat xwmin,xwmax,ywmin,ywmax2
"oid #lip($loat x),$loat y),$loat x1,$loat y1)
1
out#ode out#ode),out#ode1,out#ode+ut2
int a##ept % @AIS4,done % @AIS42
out#ode) % Comp+utCode(x),y))2
out#ode1 % Comp+utCode(x1,y1)2
do
1
i$(;(out#ode)Uout#ode1))
1
a##ept % T,?42
done % T,?42
:
else
i$(out#ode) 9 out#ode1)
done % T,?42
else
1
$loat x,y2
out#ode+ut % out#ode)Xout#ode)7out#ode12
i$(out#ode+ut 9 T+!)
1
x % x)*(x1'x))&(ywmax'y))S(y1'y))2
y % ywmax2
:
else
i$(out#ode+ut 9 B+TT+>)
1
x % x)*(x1'x))&(ywmin'y))S(y1'y))2
y % ywmin2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
:
else
i$(out#ode+ut 9 ,INWT)
1
y % y)*(y1'y))&(xwmax'x))S(x1'x))2
x % xwmax2
:
else
1
y % y)*(y1'y))&(xwmin'x))S(x1'x))2
x % xwmin2
:
i$(out#ode+ut%%out#ode))
1
x) % x2
y) % y2
out#ode) % Comp+utCode(x),y))2
:
else
1
x1 % x2
y1 % y2
out#ode1 % Comp+utCode(x1,y1)2
:::
while(done%%@AIS4)2
i$(a##ept)
line(x),y),x1,y1)2
outtextxy(1-),),6!+IEN+M A@T4, CII!!IMN6)2
re#tangle(xwmin,ywmin,xwmax,ywmax)2
:
out#ode Comp+utCode($loat x,$loat y)
1
out#ode #ode % )2
i$(y0ywmax)
#odeU%T+!2
else
i$(y(ywmin)
#odeU%B+TT+>2
i$(x0xwmax)
#odeU%,INWT2
else
i$(x(xwmin)
#odeU%I4@T2
return #ode2
:
"oid main( )
1
$loat x1,y1,x,y2
S& reAuest auto dete#tion &S
int gdri"er % 34T4CT, gmode, n,polyQ1KR,i2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
#lrs#r( )2
print$(64nter the no o$ sides o$ polygon76)2
s#an$(68d6,9n)2
print$(6Bn4nter the #oordinates o$ polygonBn6)2
$or(i%)2i(&n2i**)
1
s#an$(68d6,9polyQiR)2
:
polyQ&nR%polyQ)R2
polyQ&n*1R%polyQ1R2
print$(64nter the re#tangular #oordinates o$ #lipping windowBn6)2
s#an$(68$8$8$8$6,9xwmin,9ywmin,9xwmax,9ywmax)2
S& initialiFe graphi#s and lo#al "aria5les &S
initgraph(9gdri"er, 9gmode, 6#7BBt#BB5gi6)2

outtextxy(1-),),6!+IEN+M B4@+,4 CII!!IMN6)2
drawpoly(n*1,poly)2
re#tangle(xwmin,ywmin,xwmax,ywmax)2
get#h( )2
#learde"i#e( )2
$or(i%)2i(n2i**)
#lip(polyQ&iR,polyQ(&i)*1R,polyQ(&i)*R,polyQ(&i)*<R)2
get#h( )2
restore#rtmode( )2
:
&!P&!2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
4nter the no o$ sides o$ polygon7-
4nter the #oordinates o$ polygon
-)
-)
))
1))
<-)
<-)
T)
))
K)
T)
4nter the re#tangular #oordinates o$ #lipping window
1-)
1-)
<))
<))
PL/GN #LIPPING
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
RES&L!2
Thus the a5o"e program has 5een exe#uted and output is "eri$ied.

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
E1 N2 10 !HREE ) DIMENSINAL !RANS*RMA!IN
DA!E2

Aim 2
To write a C program to per$orm <3 trans$ormations su#h as translation, rotation, s#aling,
re$le#tion and shearing.

A3gorithm2
Step 12Start the program.
Step "23isplay the #u5e.
Step $2Input the translation "e#tor tx,ty,tF.
Step %2?sing the $un#tion line, display the o5Oe#t 5e$ore and a$ter translation.
Step (2Input the s#aling $a#tor and re$eren#e point.
Step +2?sing the $un#tion line, display the o5Oe#t 5e$ore and a$ter s#aling.
Step ,2Input the rotation angle.
Step -2?sing the $un#tion line, display the o5Oe#t 5e$ore and a$ter rotation.
Step .2Stop the !rogram.


VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
PRGRAM2
/in#lude(stdio.h0
/in#lude(#onio.h0
/in#lude(graphi#s.h0
/in#lude(math.h0
int maxx,maxy,midx,midy2
"oid axis()
1
get#h()2
#learde"i#e()2
line(midx,),midx,maxy)2
line(),midy,maxx,midy)2
:
"oid main()
1
int gd,gm,x,y,F,o,x1,x,y1,y2
dete#tgraph(9gd,9gm)2
initgraph(9gd,9gm,6 6)2
set$illstyle(),getmax#olor())2
maxx%getmaxx()2
maxy%getmaxy()2
midx%maxxS2
midy%maxyS2
axis()2
5ar<d(midx*-),midy'1)),midx*.),midy'H),-,1)2
print$(64nter Translation @a#tor6)2
s#an$(68d8d8d6,9x,9y,9F)2
axis()2
print$(6a$ter translation6)2
5ar<d(midx*(x*-)),midy'(y*1))),midx*x*.),midy'(y*H)),-,1)2
axis()2
5ar<d(midx*-),midy*1)),midx*.),midy'H),-,1)2
print$(64nter S#aling @a#tor6)2
s#an$(68d8d8d6,9x,9y,9F)2
axis()2
print$(6A$ter S#aling6)2
5ar<d(midx*(x&-)),midy'(y&1))),midx*(x&.)),midy'(y&H)),-&F,1)2
axis()2
5ar<d(midx*-),midy'1)),midx*.),midy'H),-,1)2
print$(64nter ,otating Angle6)2
s#an$(68d6,9o)2
x1%-)&#os(o&<.1KS1T))'1))&sin(o&<.1KS1T))2
y1%-)&#os(o&<.1KS1T))*1))&sin(o&<.1KS1T))2
x%.)&sin(o&<.1KS1T))'H)&#os(o&<.1KS1T))2
y%.)&sin(o&<.1KS1T))*H)&#os(o&<.1KS1T))2
axis()2
print$(6A$ter ,otation a5out Y Axis6)2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
5ar<d(midx*x1,midy'y1,midx*x,midy'y,-,1)2
axis()2
print$(6A$ter ,otation a5out D Axis6)2
5ar<d(midx*-),midy'x1,midx*.),midy'x,-,1)2
axis()2
print$(6A$ter ,otation a5out E Axis6)2
5ar<d(midx*x1,midy'1)),midx*x,midy'H),-,1)2
get#h()2
#losegraph()2
:



VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
&!P&!2
!ran@3ation
4nter Translation @a#tor 7 -) .) J)
Be$ore Translation

A$ter Translation

S5a3ing

4nter S#aling @a#tor 7 T) H) H-
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
A$ter S#aling

Rotation
4nter ,otating Angle 7 .)

A$ter ,otation a5out Y'Axis

A$ter ,otation a5out D'Axis
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING

A$ter ,otation a5out E'Axis 7

RES&L!2
Thus the a5o"e program has 5een exe#uted and output is "eri$ied.

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
E1 N2 11 #MPSI!E !HREE ) DIMENSINAL !RANS*RMA!IN
DA!E 2
Aim 2
To write a C** program to per$orm #omposite <3 trans$ormations su#h as translation,
rotation, s#aling, re$le#tion and shearing.

A3gorithm2
Step 12Start the program.
Step "2input the points $or the #ude and siFe o$ the Cu5e.
Step $23isplay the menu as 1.Translation .S#aling <.,otation K.4xit
Step %2Net the #hoi#e $rom the user.
Step (2I$ the #hoi#e is 1 a point or an o5Oe#t is translated $rom position ! to position !A with
the operation !G%T.! where t
x
,t
y
and t
F
spe#i$ying translation distan#es.
xG%x* t
x ,
yG%y* t
y,
FG%F* t
F
Step +2I$ the #hoi#e is the s#aling trans$ormation o$ a position ! #an 5e written as !G%S.!
where s#aling parameters s
x
,s
y
and s
F
are assigned any positi"e "alues.
xG%x.s
x ,
yG%y.s
y ,
FG%F.s
F
Step ,2I$ the #hoi#e is < get the rotation angle. ,otate the $igure with respe#t to the axis o$
rotation.
Step -2A5out F axis rotation xG%x#osZ'ysinZ ,yG%xsinZ*y#osZ
FG%F ,otation #an 5e expressed as !G%,
F
(Z).!
Step .2A5out x axis rotation yG%y#osZ'FsinZ FG%ysinZ*F#osZ xG%x
,otation #an 5e expressed as !G%,
x
(Z).!
Step 102A5out y axis rotation FG%F#osZ'xsinZ xG%FsinZ*x#osZ yG%y
,otation #an 5e expressed as !G%,
y
(Z).!
Step 112I$ #hoi#e is K exit the program.
Step 1"2Stop the program.
PRGRAM2
/in#lude(iostream.h0
/in#lude(graphi#s.h0
/in#lude(math.h0
/in#lude(#onio.h0
/in#lude(stdli5.h0
#lass #u5e
1
pu5li#7
"oid draw#u5e(int x1QR,int y1QR)
1
int i2
$or(i%)2i(K2i**)
1
i$(i(<)
line(x1QiR,y1QiR,x1Qi*1R,y1Qi*1R)2
line(x1Q)R,y1Q)R,x1Q<R,y1Q<R)2
:
$or(i%K2i(T2i**)
1
i$(i(J)
line(x1QiR,y1QiR,x1Qi*1R,y1Qi*1R)2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
line(x1QKR,y1QKR,x1QJR,y1QJR)2
:
$or(i%)2i(K2i**)
1
line(x1QiR,y1QiR,x1Qi*KR,y1Qi*KR)2
:
:
:2
"oid main()
1
int i,x1QTR,y1QTR,xQTR,yQTR,F1QTR,x<QTR,y<QTR,F<QTR,xKQTR,yKQTR,theta,op,#h,tx,ty,tF,sx,sy,sF,x$,y$,F$,x,y,F,siFe2
int dri"er%34T4CT2
int mode2
initgraph(9dri"er,9mode,6C7BBt#**B5gi6)2
#out((6enter the points on the #u5e762
#in00x00y00F2
#out((6enter the siFe o$ the edge762
#in00siFe2
x1Q)R%x1Q<R%x2
x1Q1R%x1QR%x*siFe2
x1QKR%x1QJR%x2
x1Q-R%x1Q.R%x*siFe2
y1Q)R%y1Q1R%y2
y1QR%y1Q<R%y*siFe2
y1QKR%y1Q-R%y2
y1Q.R%y1QJR%y*siFe2
F1Q1R%F1QR%F1Q<R%F1Q)R%F 2
F1QKR%F1Q-R%F1Q.R%F1QJR%F'siFe2
$or(i%)2i(T2i**)
1
xQiR%x1QiR*F1QiRS2
yQiR%y1QiR*F1QiRS2
:
#u5e #2
get#h()2
#learde"i#e()2
do
1
#out((6menu6((endl2
#out((6Bn1.translationBn.rotationBn<.s#alingBnK.exitBn62
#out((6enter the #hoi#e762
#in00#h2
swit#h(#h)
1
#ase 17
#out((6enter the translation "e#tor762
#in00tx00ty00tF2
$or(i%)2i(T2i**)
1
x<QiR%x1QiR*tx2
y<QiR%y1QiR*ty2
F<QiR%F1QiR*tF2
:
$or(i%)2i(T2i**)
1
xKQiR%x<QiR*F<QiRS2
yKQiR%y<QiR*F<QiRS2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
:
#learde"i#e()2
#out((65e$ore translation62
#.draw#u5e(x,y)2
get#h()2
#learde"i#e()2
#out((6a$ter translation62
#.draw#u5e(xK,yK)2
get#h()2
#learde"i#e()2
5rea=2
#ase 7
#out((6enter the rotation angle762
#in00theta2
theta%(theta&<.1K)S1T)2
#out((6enter the dire#tion6((endl2
#out((61.rotation a5out x axis6((endl((6.rotation a5out y axis6((endl((6<.rotation a5out F
axis62 #in00op2
i$(op%%1)
1
$or(i%)2i(T2i**)
1
x<QiR%x1QiR2
y<QiR%y1QiR&#os(theta)'F1QiR&sin(theta)2
F<QiR%y1QiR&sin(theta)*F1QiR&#os(theta)2
:
:
else
i$(op%%)
1
$or(i%)2i(T2i**)
1
y<QiR%y1QiR2
x<QiR%F1QiR&#os(theta)'x1QiR&sin(theta)2
x<QiR%F1QiR&sin(theta)*x1QiR&#os(theta)2
:
:
else
i$(op%%<)
1
$or(i%)2i(T2i**)
1
F<QiR%F1QiR2
x<QiR%x1QiR&#os(theta)'y1QiR&sin(theta)2
y<QiR%x1QiR&sin(theta)*y1QiR&#os(theta)2
:
:
else
#out((6enter #orre#t option62
$or(i%)2i(T2i**)
1
xKQiR%x<QiR*F<QiRS2
yKQiR%y<QiR*F<QiRS2
:
#learde"i#e()2
#out((65e$ore rotation62
#.draw#u5e(x,y)2
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
get#h()2
#learde"i#e()2
#out((6a$ter rotation62
#.draw#u5e(xK,yK)2
get#h()2
#learde"i#e()2
5rea=2
#ase <7
#out((6enter the s#aling $a#tor762
#in00sx00sy00sF2
#out((6enter the re$eren#e point762
#in00x$00y$00F$2
$or(i%)2i(T2i**)
1
x<QiR%x$*(x1QiR&sx)*x$&(1'sx)2
y<QiR%y$*(y1QiR&sy)*y$&(1'sy)2
F<QiR%F$*(F1QiR&sF)*F$&(1'sF)2
:
$or(i%)2i(T2i**)
1
xKQiR%x<QiR*F<QiRS2
yKQiR%y<QiR*F<QiRS2
:
#learde"i#e()2
#out((65e$ore s#aling62
#.draw#u5e(x,y)2
get#h()2
#learde"i#e()2
#out((6a$ter s#aling62
#.draw#u5e(xK,yK)2
get#h()2
#learde"i#e()2
5rea=2
#ase K7
exit())2
5rea=2
:
:
while(op;%K)2
get#h()2
:
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
&!P&! 2
4nter the points in the #u5e 7 1)) 1)) 1))
4nter the SiFe o$ 4dge 7 -)
>4M?
1.Translation
.,otation
<.s#aling
K.exit
4nter your #hoi#e 7 1
4nter the Translation Ce#tor - 1) 1-

4nter your Choi#e 7
Rotation
4nter the ,otation Angle 7 .)
4nter the 3ire#tion
1.,otation a5out x'axis
.,otation a5out y'axis
<.,otation a5out F'axis

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
>4M?
1.Translation
.,otation
<.s#aling
K.exit
4nter your #hoi#e 7 <
4nter the S#aling @a#tor 7 <) K) -)
4nter the ,e$eren#e point 7 ) <- K-
B4@+,4

A@T4,

VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING

RES&L!2
Thus the above progra has been e!e"uted and output is veri#ed$
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
E1 N 2 1" GENERA!ING *RA#!AL IMAGES
DA!E 2
Aim2
To generate $ra#tal images.
A3gorithm2
Step12 The Sierpins=i Triangle is #reated 5y in$inite remo"als
Step12 4a#h triangle is di"ided into K smaller upside down triangles
Step12 The #enter o$ the K triangles is remo"ed
Step12 As the pro#ess is iterated in$inite num5er o$ times, the total area o$ the
set goes to in$inity as the siFe o$ the ea#h new triangle goes to Fero
Step12 A$ter #loser examination magni$i#ation $a#tor is .
Step12 Vith ea#h magni$i#ation there are < di"isions o$ a triangle
3imension 3%ln(<)Sln()
3%1.-T-)
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
PRGRAM
/in#lude (stdio.h0
/in#lude (#onio.h0
/in#lude (stdli5.h0
/in#lude (math.h0
/in#lude (graphi#s.h0
"oid 3rawSierpins=i("oid)2
"oid main("oid)
1
int gd%CNA2
int gm%CNAWI2
initgraph(9gd, 9gm, 6BBt#BB5gi6)2
3rawSierpins=i()2
get#h()2
:
"oid 3rawSierpins=i("oid)
1
#har 3ire#t2
int iterate2
unsigned int x1, y1, x, y2
x1 % x % <)2
y1 % y % )2
$or(iterate % )2 iterate ( 1))))2 iterate**)
1
3ire#t % random(<)2
i$(3ire#t %% ))
1
x1 % (x * <)) S 2
y1 % (y * )) S 2
:
else i$(3ire#t %% 1)
1
x1 % (x * )) S 2
y1 % (y * KT)) S 2
:
else i$(3ire#t %% )
1
x1 % (x * .K)) S 2
y1 % (y * KT)) S 2
:
putpixel(x1, y1, VWIT4)2
x % x12
y % y12
:
:
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING
&!P&! 2
RES&L!2
Thus generation o$ Sierpins=i triangle using the a5o"e program has 5een exe#uted and output
is "eri$ied.
VINOTHA S R
DHANALAKSHMI COLLEGE OF ENGINEERING

You might also like