Professional Documents
Culture Documents
Computer Graphics Lab Manual
Computer Graphics Lab Manual
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