Vous êtes sur la page 1sur 46

Expt no : 1a

Date :
Drawing line using Bresenham algorithm
Aim:
To draw line using bresenham algorithm in c.
Algorithm:
1.Input two line endpoints
2.Obtain starting value for the decision parameter as
P0=2!"
#.If p$%0 the ne"t point to plot is &"$'1($) and p$'1=p$'2 else ne"t point to plot is &"$'1($'1) and
p$'1=p$'2!2"
*.+epeat step # " times.
Coding:
,include%stdio.h-
,include%conio.h-
,include%math.h-
,include%graphics.h-
main&)
.
int gd=/0T01T(gm2
int "a("b(a(b2
int d"(d(3(4(3end(p(b2
initgraph&5gd(5gm(6c788tc88bgi6)2
printf&609T0+ T:O ;0<T 09/ POI9T=6)2
scanf&6>d>d6(5"a(5a)2
printf&609T0+ T:O +I?@T 09/ POI9T= 6)2
scanf&6>d>d6(5"b(5b)2
d"=abs&"a!"b)2
d=abs&a!b)2
p=2Ad!d"2
if&"a-"b)
.
3="b2
4=b2
3end="a2
B
else
.
3="a2
4=a2
3end="b2
B
putpi"el&3(4(b)2
while&3%3end)
.
3=3'12
if&p%0)
.
p=p'2Ad2
B
else
.
4=4'12
p=p'2A&d!d")2
B
putpi"el&3(4(b)2
B
getch&)2
return&0)2
B
OUTPUT:
0nter two left endpoints7
100
200
0nter two right endpoints7
#00
*00
RESUT:
The line was drawn using bresenham algorithm successfull.
0"pt no 7 1b
/ate 7
Drawing !ir!le using Bresenham algorithm
Aim:
To draw circle using bresenham algorithm in c.
Algorithm:
1.Input radius r and circle center&"c(c)
2.calculate the initial value of the decision parameter as
P0=CD*!r
#.If p$%0( the ne"t point along the circle is calculated as p$'1=p$'2"$'1'1 otherwise calculate using
p$'1=p$'2"$'1'1!2$'1
*.+epeat step # until "-=.
COD"#$:
,include 6stdio.h6
,include 6conio.h6
,include 6math.h6
,include 6graphics.h6
main&)
.
int gd=/0T01T(gm2
int "center(center(radius2
int p("(2
initgraph&5gd(5gm(6c788tc88bgi6)2
"=02
printf&60nter The +adius Ealue78n6)2
scanf&6>d6(5radius)2
=radius2
printf&60nter The "center and center Ealues78n6)2
scanf&6>d>d6(5"center(5center)2
plotpoints&"center(center("()2
p=1!radius2
while&"%)
. if&p%0)
"="'12
else
.
"="'12
=!12
B
if&p%0)
p=p'2A"'12
else
p=p'2A&"!)'12
plotpoints&"center(center("()2
B
getch&)2
return&0)2
B
int plotpoints&int "center(int center(int "(int )
.
putpi"el&"center'"(center'(1)2
putpi"el&"center!"(center'(1)2
putpi"el&"center'"(center!(1)2
putpi"el&"center!"(center!(1)2
putpi"el&"center'(center'"(1)2
putpi"el&"center!(center'"(1)2
putpi"el&"center'(center!"(1)2
B
OUTPUT:
0nter The +adius Ealue7
100
0nter The "center and center Ealues7
100
200
RESUT:
The circle was drawn using bresenham algorithm successfull.
Expt no : 1!
Date :
Drawing ellipse using Bresenham algorithm
Aim:
To draw ellipse using bresenham algorithm in c.
Algorithm:
1.Input ellipse center and maFor( minor a"is
2.Obtain starting value for the decision parameter as p1=&bAb)!&aAaAa)A&aAa)D* and p2=&aAa)
'&2.0AbAbAa)'&bAb)D*
#.If p1%=10 the ne"t point to plot calculated using p1=p1'&2.0AbAbA")'&bAb) else ne"t point to plot is
calculated using p1=p1'&2.0AbAbA")'&bAb)!&2.0AaAaA)
*. .If p2-0 the ne"t point to plot calculated using p2=p2'&aAa)!&2.0AaAaA) else ne"t point to plot is
calculated using p2=p2'&2.0AbAbA")!&2.0AaAaA)'&aAa)
C.+epeat step # and * until 2.0AbAbA" - 2.0AaAaA.
COD"#$:
,include 6stdio.h6
,include 6conio.h6
,include 6math.h6
,include 6graphics.h6
main&)
.
int gd=/0T01T(gm2
int "center(center(r"(r2
int p("((p"(p(r"1(r1(r"2(r22
initgraph&5gd(5gm(6c788tc88bgi6)2
printf&60nter The +adius Ealue78n6)2
scanf&6>d>d6(5r"(5r)2
printf&60nter The "center and center Ealues78n6)2
scanf&6>d>d6(5"center(5center)2
r1=rAr2
r"1=r"Ar"2
r2=2Ar12
r"2=2Ar"12
"=02
=r2
plotpoints&"center(center("()2
p=&r1!r"1Ar'&0.2CAr"1))2
p"=02
p=r"2A2
while&p"%p)
.
"="'12
p"=p"'r22
if&p-=0)
=!12
p=p!r"22
if&p%0)
p=p'r1'p"2
else
p=p'r1'p"!p2
plotpoints&"center(center("()2
p=&r1A&"'0.C)A&"'0.C)'r"1A&!1)A&!1)!r"1Ar1)2
while&-0)
.
=!12
p=p!r"22
if&p%=0)
.
"="'12
p"=p"'r22
B
if&p-0)
p=p'r"1!p2
else
p=p'r"1!p'p"2
plotpoints&"center(center("()2
B
OUTPUT:
0nter The +adius Ealue7
20
10
0nter The "center and center Ealues7
200
100
RESUT:
The ellipse was drawn using bresenham algorithm successfull.
0"pt no 7 2
/ate 7
"mplementation o% line&!ir!le&ellipse attri'utes
Aim:
To appl the various attributes of line( circle and ellipse in c.
Algorithm:
1.Gse predefined functions line( circle and ellipse to draw line( circle and ellipse shapes with specified
parameter values.
2.setcolor method used to set the color of the shapes.
#.setfillsle method sets the stle of the shapes.
*.outte"t" method used to draw the given te"t.
1O/I9?7
,include%stdio.h-
,include%conio.h-
,include%graphics.h-
,include%stdlib.h-
,include%string.h-
void main&).
int gdriver=/0T01T(gmode2
initgraph&5gdriver(5gmode(6c788tc88bgi6)2
setcolor&11)2
setfillstle&11(1*)2
line&#00(200(C00(200)2
circle&#00(#00(C0)2
ellipse&C00(100(0(#H0(I0(*0)2
outte"t"&*00(*00(6@0;;O6)2
setlinestle&*(I(#)2
fillellipse&C00(100(I0(*0)2
getch&)2
closegraph&)2
B
OUTPUT:
@0;;O
RESUT: The Implementation of line( circle( ellipse using attributes was verified
successfull.
0"pt no 7#
/ate 7
(D TRA#S)OR*AT"O#
Aim:
To appl transformation to 2!/imensional shapes in c.
Algorithm:
1.Input upper left corner and lower right corner of the rectangle.
2.To translate the rectangle appl formula "1="'t" and 1='t
#.To rotate the rectangle appl
a1=&"a'&&a!"a)Acos&theta)!&b!a)Asin&theta)))
b1=&a'&&a!"a)Asin&theta)!&b!a)Acos&theta)))
*.To scale the rectangle siJe
"1="As"2
1=As2
C.+eflection
a1=&"a'&&a!"a)Acos&theta)!&!b!a)Asin&theta)))
b1=&a'&&a!"a)Asin&theta)'&!b!a)Acos&theta)))
H.=hearing
"1="'&A"1s)
1=
aJ1=aJ'&wA"1s)
w1=w
COD"#$:
, include%graphics.h-
, include%stdio.h-
, include%conio.h-
, include%math.h-
void main&)
.
int gd=/0T01T(gm(i(F($(ch2
float t"(t("((ang(n(temp2
float aKCLK#L(si(co(bKCLK#L(cKCLK#L2
initgraph&5gd(5gm(6e788tcpp88bgi6)2
n=*2
aK0LK0L=02 aK0LK1L=02 aK1LK0L=1002 aK1LK1L=02
aK2LK0L=1002 aK2LK1L=1002 aK#LK0L=02 aK#LK1L=1002
aK*LK0L=02 aK*LK1L=02
while&1)
.
cleardevice&)2
goto"&1(M)2
printf&68n8tAAAAAAAA Program to perform 2!/ Transformations AAAAAAAA6)2
printf&68n8t8t8t 1. Nccept the polgon6)2
printf&68n8t8t8t 2. Perform translation6)2
printf&68n8t8t8t #. Perform scaling6)2
printf&68n8t8t8t *. Perform rotation6)2
printf&68n8t8t8t C. Perform reflection6)2
printf&68n8t8t8t H. Perform shearing6)2
printf&68n8t8t8t I. 0"it6)2
printf&68n8t8t8t 0nter our choice776)2
scanf&6>d6(5ch)2
switch&ch)
.
case 17
cleardevice&)2
goto"&1(1)2
printf&68n8t0nter no of points.76)2
scanf&6>f6(5n)2
for&i=02i%n2i'')
.
printf&68n8t 0nter "( co!ordinates for >d776(i'1)2
scanf&6>f >f6(5aKiLK0L(5aKiLK1L)2 B
aKiLK0L=aK0LK0L2
aKiLK1L=aK0LK1L2
cleardevice&)2
for&i=02i%n2i'')
line&#20'aKiLK0L(2*0!aKiLK1L(#20'aKi'1LK0L(2*0!aKi'1LK1L)2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
getch&)2
brea$2
case 27
cleardevice&)2
for&i=02i%n2i'')
line&#20'aKiLK0L(2*0!aKiLK1L(#20'aKi'1LK0L(2*0!aKi'1LK1L)2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
goto"&1(1)2
printf&60nter translation vectors t" and t8n8t6)2
scanf&6>f >f6(5"(5)2
cleardevice&)2
for&i=02i%n2i'')
line&#20'aKiLK0L'"(2*0!&aKiLK1L')(#20'aKi'1LK0L'"(2*0!&aKi'1LK1L'))2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
getch&)2
brea$2
case #7
cleardevice&)2
for&i=02i%n2i'')
line&#20'aKiLK0L(2*0!aKiLK1L(#20'aKi'1LK0L(2*0!aKi'1LK1L)2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
goto"&1(1)2
printf&60nter scaling vectors t" and t8n8t6)2
scanf&6>f >f6(5"(5)2
if&"==0)
"=12
if&==0)
=12
cleardevice&)2
for&i=02i%n2i'')
line&#20'&aKiLK0LA")(2*0!&aKiLK1LA)(#20'&aKi'1LK0LA")(2*0!&aKi'1LK1LA))2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
getch&)2
brea$2
case *7
cleardevice&)2
for&i=02i%n2i'')
line&#20'aKiLK0L(2*0!aKiLK1L(#20'aKi'1LK0L(2*0!aKi'1LK1L)2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
goto"&1(1)2
printf&60nter the angle of rotation8n8t6)2
scanf&6>f6(5ang)2
ang=angA0.01I*C2
goto"&1(#)2
printf&60nter point of rotation8n8t6)2
scanf&6>f >f6(5"(5)2
goto"&1(C)2
printf&61.cloc$wise 2.anticloc$wise8n8t6)2
scanf&6>d6(5$)2
si=sin&ang)2
co=cos&ang)2
for&i=02i%n'12i'')
. cKiLK0L=aKiLK0L2
cKiLK1L=aKiLK1L2
cKiLK2L=12B
bK0LK0L=co2
bK0LK1L=si2
bK0LK2L=02
bK1LK0L=&!si)2
bK1LK1L=co2
bK1LK2L=02
bK2LK0L=&!"Aco)'&Asi)'"2
bK2LK1L=&!"Asi)!&Aco)'2
bK2LK2L=12
if&$==1)
.bK0LK1L=&!si)2
bK1LK0L=&si)2
bK2LK0L=&!"Aco)!&Asi)'"2
bK2LK1L=&!"Asi)'&Aco)'2B
for&i=02i%n'12i'')
.
for&F=02F%#2F'')
. aKiLKFL = 0 2
for&$=02$%#2$'')
aKiLKFL = aKiLKFL ' cKiLK$L A bK$LKFL 2BB
cleardevice&)2
for&i=02i%n2i'')
line&#20'aKiLK0L(2*0!aKiLK1L(#20'aKi'1LK0L(2*0!aKi'1LK1L)2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
getch&)2
brea$2
case C7
cleardevice&)2
for&i=02i%n2i'')
line&#20'aKiLK0L(2*0!aKiLK1L(#20'aKi'1LK0L(2*0!aKi'1LK1L)2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
goto"&1(1)2
printf&68n1.+eflection about 4!a"is6)2
printf&68n2.+eflection about 3!a"is6)2
printf&68n#.+eflection about origin6)2
printf&68n*.+eflection about line ="6)2
printf&68nC.+eflection about line =!"6)2
printf&68n0nter our choice76)2
scanf&6>d6(5ch)2
switch&ch)
.
case 17
for&i=02i%n'12i'')
aKiLK0L=aKiLK0LA&!1)2
DA Plot the polgon AD
cleardevice&)2
for&i=02i%n2i'')
line&#20'aKiLK0L(2*0!aKiLK1L(#20'aKi'1LK0L(2*0!aKi'1LK1L)2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
getch&)2
brea$2
case 27
for&i=02i%n'12i'')
aKiLK1L=aKiLK1LA&!1)2
cleardevice&)2
for&i=02i%n2i'')
line&#20'aKiLK0L(2*0!aKiLK1L(#20'aKi'1LK0L(2*0!aKi'1LK1L)2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
getch&)2
brea$2
case #7
for&i=02i%n'12i'')
. aKiLK1L=aKiLK1LA&!1)2
aKiLK0L=aKiLK0LA&!1)2 B
cleardevice&)2
for&i=02i%n2i'')
line&#20'aKiLK0L(2*0!aKiLK1L(#20'aKi'1LK0L(2*0!aKi'1LK1L)2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
getch&)2
brea$2
case *7
for&i=02i%n'12i'')
. temp=aKiLK0L2
aKiLK0L=aKiLK1L2
aKiLK1L=temp2B
cleardevice&)2
for&i=02i%n2i'')
line&#20'aKiLK0L(2*0!aKiLK1L(#20'aKi'1LK0L(2*0!aKi'1LK1L)2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
line&0(*IO(H#O(0)2
getch&)2
brea$2
case C7
for&i=02i%n'12i'')
. temp=aKiLK0L2
aKiLK0L=aKiLK1L2
aKiLK1L=temp2 B
for&i=02i%n'12i'')
. aKiLK1L=aKiLK1LA&!1)2
aKiLK0L=aKiLK0LA&!1)2B
cleardevice&)2
for&i=02i%n2i'')
line&#20'aKiLK0L(2*0!aKiLK1L(#20'aKi'1LK0L(2*0!aKi'1LK1L)2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
line&0(0(H#O(*IO)2
getch&)2
brea$2
default7
brea$2
B
brea$2
case H7
cleardevice&)2
for&i=02i%n2i'')
line&#20'aKiLK0L(2*0!aKiLK1L(#20'aKi'1LK0L(2*0!aKi'1LK1L)2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
goto"&1(1)2
printf&68n1.3 shear with reference line6)2
printf&68n2.4 shear with " reference line6)2
printf&68n0nter our choice76)2
scanf&6>d6(5ch)2
switch&ch)
.
case 17
printf&68n0nter the "!shear parameter value76)2
scanf&6>f6(5temp)2
printf&68n0nter the ref line6)2
scanf&6>f6(5t)2
bK0LK0L=12
bK0LK1L=02
bK0LK2L=02
bK1LK0L=temp2
bK1LK1L=12
bK1LK2L=02
bK2LK0L=&!temp)A&t)2
bK2LK1L=02
bK2LK2L=12
for&i=02i%n'12i'')
aKiLK2L=12
for&i=02i%n'12i'')
.for&F=02F%#2F'').
cKiLKFL = 0 2
for&$=02$%#2$'')
cKiLKFL = cKiLKFL ' aKiLK$L A bK$LKFL 2BB
cleardevice&)2
for&i=02i%n2i'')
line&#20'cKiLK0L(2*0!cKiLK1L(#20'cKi'1LK0L(2*0!cKi'1LK1L)2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
getch&)2
brea$2
case 27
printf&68n0nter the !shear parameter value76)2
scanf&6>f6(5temp)2
printf&68n0nter the "ref line6)2
scanf&6>f6(5t")2
bK0LK0L=12
bK0LK1L=temp2
bK0LK2L=02
bK1LK0L=02
bK1LK1L=12
bK1LK2L=02
bK2LK0L=02
bK2LK1L=&!temp)A&t")2
bK2LK2L=02
for&i=02i%n'12i'')
aKiLK2L=12
for&i=02i%n'12i'')
. for&F=02F%#2F'')
. cKiLKFL = 0 2
for&$=02$%#2$'')
cKiLKFL = cKiLKFL ' aKiLK$L A bK$LKFL 2 BB
cleardevice&)2
for&i=02i%n2i'')
line&#20'cKiLK0L(2*0!cKiLK1L(#20'cKi'1LK0L(2*0!cKi'1LK1L)2
line&0(2*0(H#O(2*0)2
line&#20(0(#20(*IO)2
getch&)2
brea$2
default7 brea$2 B
brea$2
case I7
e"it&1)2
closegraph&)2
restorecrtmode&)2
brea$2
default7 brea$2
B
B
B
OGTPGT7
AAAAAAAA Program to perform 2!/ Transformations AAAAAAAA
1. Nccept the polgon
2. Perform translation
#. Perform scaling
*. Perform rotation
C. Perform reflection
H. Perform shearing
0nter our choice7 1
0nter no of points7 *
0nter "( co!ordinates for 17100 1C0
0nter "( co!ordinates for 27200 100
0nter "( co!ordinates for #71C0 100
0nter "( co!ordinates for *7200 100
0nter our choice7 2
0nter translation vectors t" and t7 C0 C0
0nter our choice7 #
0nter scaling vectors t" and t70.C 0.C
0nter our choice7 *
0nter the angle of rotation7O0
0nter point of rotation72C 20
1.cloc$wise 2.anticloc$wise 1
0nter our choice7 C
1.+eflection about 4!a"is
2.+eflection about 3!a"is
#.+eflection about origin
*..+eflection about line ="
C.+eflection about line =!"
0nter our choice71
0nter our choice7 C
1.3 shear with reference line
2.4 shear with " reference line
0nter our choice71
0nter the "!shear parameter value70.# 0.#
RESUT: The rotation(scaling(reflection(shearing is implemented successfull.
Exptno: +
Date :
CO*POS"TE (D TRA#S)OR*AT"O#
Aim:
To appl composite transformation to 2!/imensional shapes in c.
Algorithm:
1.Input upper left corner and lower right corner of the rectangle.
2.To multiple translation the rectangle appl formula "1="'t" and 1='t
#.To rotate multiple times the rectangle appl
a1=&"a'&&a!"a)Acos&theta)!&b!a)Asin&theta)))
b1=&a'&&a!"a)Asin&theta)!&b!a)Acos&theta)))
*.To composite scale the rectangle siJe
"1="As"2
1=As2
C.1omposite +eflection
a1=&"a'&&a!"a)Acos&theta)!&!b!a)Asin&theta)))
b1=&a'&&a!"a)Asin&theta)'&!b!a)Acos&theta)))
H. 1omposite =hearing
"1="'&A"1s)2
1=2
aJ1=aJ'&wA"1s)2
w1=w2
Program:
,include%stdio.h-
,include%conio.h-
,include%graphics.h-
,include%math.h-
int ch("((aJ(i(w(ch1(ch2("a(a(ra(ra1(aK10L(bK10L(da(db2
float "1(1(aJ1(w1(d"1(d1(d"2(d2(theta(theta1("1s(1s(s"2(s2(s"1(s1(a1K10L(b1K10L2
void main&).
int gd(gm2
clrscr&)2
detectgraph&5gd(5gm)2
initgraph&5gd(5gm(6c788tc88bgi6)2
printf&68n0nter the upper left corner of the rectangle76)2
scanf&6>d>d6(5"(5)2
printf&68n0nter the lowest right corner of the rectangle76)2
scanf&6>d>d6(5aJ(5w)2
rectangle&"((aJ(w)2
da=aJ!"2
db=w!2
aK0L="2
bK0L=2
aK1L="'da2
bK1L=2
aK2L="'da2
bK2L='db2
aK#L="2
bK#L='db2
while&1).
printf&68nAAAAA1omposite 2/ TransformationsAAAAAA6)2
printf&68n1.Translation8n2.+otation8n#.=caling8n*.0"it8n 0nter our choice76)2
scanf&6>d6(5ch)2
switch&ch).
case 17
detectgraph&5gd(5gm)2
initgraph&5gd(5gm(6c788tc88bgi6)2
rectangle&"((aJ(w)2
printf&68nAAAAATranslationAAAAAA6)2
printf&68n0nter the value of 1st shift factor76)2
scanf&6>f>f6(5d"1(5d1)2
printf&68n0nter the value of 2nd shift factor76)2
scanf&6>f>f6(5d"2(5d2)2
"1="'d"12
1='d12
aJ1=aJ'd"12
w1=w'd12
rectangle&"1(1(aJ1(w1)2
"1="1'd"22
1=1'd22
aJ1=aJ1'd"22
w1=w1'd22
rectangle&"1(1(aJ1(w1)2
brea$2
case 27
detectgraph&5gd(5gm)2
initgraph&5gd(5gm(6c788tc88bgi6)2
rectangle&"((aJ(w)2
printf&68nAAAAA+otationAAAAAA6)2
printf&68n0nter the value of fi"ed point76)2
scanf&6>d>d6(5"a(5a)2
printf&68n0nter the value of angle of rotation 1 5 rotation 276)2
scanf&6>d>d6(5ra(5ra1)2
theta=&float)&raA&#.1*D1M0))2
for&i=02i%*2i'').
a1KiL=&"a'&&aKiL!"a)Acos&theta)!&bKiL!a)Asin&theta)))2
b1KiL=&a'&&aKiL!"a)Asin&theta)'&bKiL!a)Acos&theta)))2
B
for&i=02i%*2i'').
if&iP=#)
line&a1KiL(b1KiL(a1Ki'1L(b1Ki'1L)2
else
line&a1KiL(b1KiL(a1K0L(b1K0L)2
B
theta1=theta'&float)&ra1A&#.1*D1M0))2
for&i=02i%*2i'').
a1KiL=&"a'&&aKiL!"a)Acos&theta1)!&bKiL!a)Asin&theta1)))2
b1KiL=&a'&&aKiL!"a)Asin&theta1)'&bKiL!a)Acos&theta1)))2
B
for&i=02i%*2i'').
if&iP=#)
line&a1KiL(b1KiL(a1Ki'1L(b1Ki'1L)2
else
line&a1KiL(b1KiL(a1K0L(b1K0L)2
B
brea$2
case #7
detectgraph&5gd(5gm)2
initgraph&5gd(5gm(6c788tc88bgi6)2
rectangle&"((aJ(w)2
printf&68nAAAAA=calingAAAAAA6)2
printf&68n0nter the value of =caling factor176)2
scanf&6>f>f6(5s"1(5s1)2
printf&68n0nter the value of =caling factor276)2
scanf&6>f>f6(5s"2(5s2)2
"1="As"12
1=As12
aJ1=aJAs"12
w1=wAs12
rectangle&"((aJ1(w1)2
"1="1As"22
1=1As22
aJ1=aJ1As"22
w1=w1As22
rectangle&"1(1(aJ1(w1)2
brea$2
case *7
e"it&0)2
B
getch&)2
B
B
Output:
0nter the upper left corner of the rectangle7
100
100
0nter the lower right corner of the rectangle7
200
200
AAAAAA2/TransformationsAAAAAAA
1.Translation
2.+otation
#.=caling
*.0"it
0nter our choice7 1
AAAAAAATranslationAAAAAAA
0nter the value of 1st shift factor7 C0 C0
0nter the value of 2nd shift factor7 100 100
AAAAAA2/TransformationsAAAAAAA
1.Translation
2.+otation
#.=caling
*.0"it
0nter our choice7 2
AAAAAAA+otationAAAAAAA
0nter the value of fi"ed point7
200
200
0nter the value of angle of rotation 1 5 rotation 27 C0 I0
AAAAAA2/TransformationsAAAAAAA
1.Translation
2.+otation
#.=caling
*.0"it
0nter our choice7 #
AAAAAAAA=calingAAAAAAA
0nter the value of =caling factor17 2 2
0nter the value of =caling factor27 2 2
Result:
Thus the program was e"ecuted successfull.
E,-#O-:.
Date : CO/E#0SUT/ERA#D "#E C"PP"#$
Aim: To clip the lines fallen outside the window using cohen =utherland line clipping algorithm.
Algorithm:
1.Input two line endpoints
2.1alculate the differences between the endpoints and clipping boundaries
#.if line as to be clipped left side of the window p1&")="!"wmin and to clip right side set p2&")="wma"!"
*. if line as to be clipped down side of the window p2&)=!wmin and to clip upper side set p2&)=wma"!
Program:
,include%iostream.h-
,include%graphics.h-
,include%conio.h-
,include%stdlib.h-
tpedef struct coord.
int "(2
char codeK*L2
Bpt2
class sulc.
public7
void drawwindow&)2
void drawline&pt p1(pt p2(int c1)2
pt setcode&pt p)2
int visibilit&pt p1(pt p2)2
pt resetendpt&pt p1(pt p2)2
B2
void sulc77drawwindow&).
setcolor&12)2
line&1C0(100(*C0(100)2
line&*C0(100(*C0(#C0)2
line&*C0(#C0(1C0(#C0)2
line&1C0(#C0(1C0(100)2
B
void sulc77drawline&pt p1(pt p2(int c1).
setcolor&c1)2
line&p1."(p1.(p2."(p2.)2
B
pt sulc77setcode&pt p).
pt ptemp2
if&p.%100)
ptemp.codeK0L=Q1Q2
else
ptemp.codeK0L=Q0Q2
if&p.-#C0)
ptemp.codeK1L=Q1Q2
else
ptemp.codeK1L=Q0Q2
if&p."-*C0)
ptemp.codeK2L=Q1Q2
else
ptemp.codeK2L=Q0Q2
if&p."%1C0)
ptemp.codeK#L=Q1Q2
else
ptemp.codeK#L=Q0Q2
ptemp."=p."2
ptemp.=p.2
return&ptemp)2
B
int sulc77visibilit&pt p1(pt p2).
int i(flag=02
for&i=02i%*2i'').
if&&p1.codeKiLP=Q0Q)RR&p2.codeKiLP=Q0Q))
flag=12
B
if&flag==0)
return&0)2
for&i=02i%*2i'').
if&&p1.codeKiL==p2.codeKiL)55&p1.codeKiL==Q1Q))
flag=02
B
if&flag==0)
return&1)2
return&2)2
B
pt sulc77resetendpt&pt p1(pt p2).
pt temp2
int "((i2
float m($2
if&p1.codeK#L==Q1Q)
"=1C02
if&p1.codeK2L==Q1Q)
"=*C02
if&&p1.codeK#L==Q1Q)RR&p1.codeK2L==Q1Q)).
m=&float)&p2.!p1.)D&p2."!p1.")2
$=&p1.'&mA&"!p1.")))2
temp.=$2
temp."="2
for&i=02i%*2i'')
temp.codeKiL=p1.codeKiL2
if&temp."%=*C055temp."-=1C0)
return&temp)2
B
if&p1.codeK0L==Q1Q)
=1002
if&p1.codeK1L==Q1Q)
=#C02
if&&p1.codeK0L==Q1Q)RR&p1.codeK1L==Q1Q)).
m=&float)&p2.!p1.)D&p2."!p1.")2
$=&float)p1."'&float)&!p1.)Dm2
temp."=$2
temp.=2
for&i=02i%*2i'')
temp.codeKiL=p1.codeKiL2
if&temp.%=#C055temp.-100)
return&temp)2
B
else
return&p1)2
B
void main&).
int gd=/0T01T(gm(v2
sulc c12
pt p1(p2(ptemp2
initgraph&5gd(5gm(6c788tc88bgi6)2
int "1K10L(1K10L("2K10L(2K10L2
cleardevice&)2
int i(n2
sette"tstle&*(0(*)2
outte"t&68nAAAAA1ohen =utherland ;ine 1lippingAAAAA6)2
cout%%68n8n8n0nter the no. of lines762
cin--n2
for&i=02i%n2i'').
cout%%68n0nter end point1&"1(1)762
cin--"1KiL--1KiL2
cout%%68n0nter end point2&"2(2)762
cin--"2KiL--2KiL2
B
cleardevice&)2
sette"tstle&0(0(#)2
outte"t&68nSefore 1lipping6)2
c1.drawwindow&)2
for&i=02i%n2i'').
p1."="1KiL2
p1.=1KiL2
p2."="2KiL2
p2.=2KiL2
c1.drawline&p1(p2(1C)2
B
getch&)2
cleardevice&)2
sette"tstle&0(0(#)2
outte"t&68nNfter 1lipping6)2
for&i=02i%n2i'').
p1."="1KiL2
p1.=1KiL2
p2."="2KiL2
p2.=2KiL2
p1=c1.setcode&p1)2
p2=c1.setcode&p2)2
v=c1.visibilit&p1(p2)2
switch&v).
case 07
c1.drawwindow&)2
c1.drawline&p1(p2(1C)2
brea$2
case 17
c1.drawwindow&)2
brea$2
case 27
p1=c1.resetendpt&p1(p2)2
p2=c1.resetendpt&p2(p1)2
c1.drawwindow&)2
c1.drawline&p1(p2(1C)2
brea$2
B
B
getch&)2
closegraph&)2
B
Output:
0nter the no.of lines7 1
0nter end!point1&"1(1)7#0 *0
0nter end!point1&"2(2)7#00 *00
Sefore clipping
Nfter clipping
Result:
Thus the program was e"ecuted successfull.
E,-#O-:1
Date : /OD$E*A# SUT/ERA#D PO2$O# C"PP"#$
Aim:
To clip the polgon region fallen outside the window using @odgeman =utherland polgon clipping
algorithm.
Algorithm:
1.if first verte" is outside the window boundar and the second verte" is inside( both the intersection point
of the polgon edge with window boundar and the second verte" are added to the output verte" list
2.if both input vertices are inside the window( onl the second verte" is added to the output verte" list
#.if the first verte" is inside the window boundar and the second verte" is outside( onl the edge
intersection with the window boundar is added to the output verte" list
*. if both input vertices are outside the window boundar( nothing is added to the output list.
Program:
,include%iostream.h-
,include%conio.h-
,include%graphics.h-
,define round&a) &&int)&a'0.C))
int $2
float "min(min("ma"(ma"(arrK20L(m2
void clipl&float "1(float 1(float "2(float 2).
if&"2!"1)
m=&2!1)D&"2!"1)2
else
m=1000002
if&"1-="min 55 "2-="min).
arrK$L="22
arrK$'1L=22
$'=22
B
if&"1%"min 55 "2-="min).
arrK$L="min2
arrK$'1L=1'mA&"min!"1)2
arrK$'2L="22
arrK$'#L=22
$'=*2
B
if&"1-="min 55 "2%"min).
arrK$L="min2
arrK$'1L=1'mA&"min!"1)2
$'=22
B
B
void clipt&float "1(float 1(float "2(float 2).
if&2!1)
m=&"2!"1)D&2!1)2
else
m=1000002
if&1%=ma" 55 2%=ma").
arrK$L="22
arrK$'1L=22
$'=22 B
if&1-ma" 55 2%=ma").
arrK$L="1'mA&ma"!1)2
arrK$'1L=ma"2
arrK$'2L="22
arrK$'#L=22
$'=*2
B
if&1%=ma" 55 2-ma").
arrK$L="1'mA&ma"!1)2
arrK$'1L=ma"2
$'=22
BB
void clipr&float "1(float 1(float "2(float 2).
if&"2!"1)
m=&2!1)D&"2!"1)2
else
m=1000002
if&"1%="ma" 55 "2%="ma").
arrK$L="22
arrK$'1L=22
$'=22
B
if&"1-"ma" 55 "2%="ma").
arrK$L="ma"2
arrK$'1L=1'mA&"ma"!"1)2
arrK$'2L="22
arrK$'#L=22
$'=*2
B
if&"1%="ma" 55 "2-"ma").
arrK$L="ma"2
arrK$'1L=1'mA&"ma"!"1)2
$'=22
BB
void clipb&float "1(float 1(float "2(float 2).
if&2!1)
m=&"2!"1)D&2!1)2
else
m=1000002
if&1-=min 55 2-=min).
arrK$L="22
arrK$'1L=22
$'=22
B
if&1%min 55 2-=min).
arrK$L="1'mA&min!1)2
arrK$'1L=min2
arrK$'2L="22
arrK$'#L=22
$'=*2
B
if&1-=min 55 2%min).
arrK$L="1'mA&min!1)2
arrK$'1L=min2
$'=22
BB
void main&).
int gdriver=/0T01T(gmode(n(polK20L2
float "i(i("f(f(polK20L2
clrscr&)2
cout%%61oordinates of rectangular clip window78n "min(min762
cin--"min--min2
cout%%6"ma"(ma"762
cin--"ma"--ma"2
cout%%68n8n Polgon to be clipped78n 9umber of sides762
cin--n2
cout%%60nter the coordinates762
for&int i=02i%2An2i'')
cin--polKiL2
polKiL=polK0L2
polKi'1L=polK1L2
for&i=02i%2An'22i'')
polKiL=round&polKiL)2
initgraph&5gdriver(5gmode(6c788tc88bgi6)2
setcolor&+0/)2
rectangle&"min(ma"("ma"(min)2
cout%%68t8t G91;IPP0/ PO;4?O962
setcolor&:@IT0)2
fillpol&n(pol)2
getch&)2
cleardevice&)2
$=02
for&i=02i%2An2i'=2)
clipl&polKiL(polKi'1L(polKi'2L(polKi'#L)2
n=$D22
for&i=02i%$2i'')
polKiL=arrKiL2
polKiL=polK0L2
polKi'1L=polK1L2
$=02
for&i=02i%2An2i'=2)
clipt&polKiL(polKi'1L(polKi'2L(polKi'#L)2
n=$D22
for&i=02i%$2i'')
polKiL=arrKiL2
polKiL=polK0L2
polKi'1L=polK1L2
$=02
for&i=02i%2An2i'=2)
clipr&polKiL(polKi'1L(polKi'2L(polKi'#L)2
n=$D22
for&i=02i%$2i'')
polKiL=arrKiL2
polKiL=polK0L2
polKi'1L=polK1L2
$=02
for&i=02i%2An2i'=2)
clipb&polKiL(polKi'1L(polKi'2L(polKi'#L)2
for&i=02i%$2i'')
polKiL=round&arrKiL)2
if&$)
fillpol&$D2(pol)2
setcolor&+0/)2
rectangle&"min(ma"("ma"(min)2
cout%%68t 1;IPP0/ PO;4?O962
getch&)2
closegraph&)2
B
Output:
1oordinates of rectangular clip window7
"min(min7 100 200
"ma"(ma"7 #C0 *00
Polgon to be clipped7
9umber of sides *
0nter the coordinates IC #00 2C0 100 #00 #00 2C0 *C0
U#C"PPED PO2$O#
C"PPED PO2$O#
Result: Thus the program was e"ecuted successfull.
E,-#O-: 3
Date : 4D TRA#S)OR*AT"O#
Aim:
To appl transformation to #!/imensional shapes in c''.
Algorithm:
1.To translate the cube appl formula
"#="1't"
#=1't
J#=J1'tJ
2.To rotate the cube appl
"#="12
#=1Acos&theta)!J1Asin&theta)
J#=1Asin&theta)'J1Acos&theta)
#.To scale the cube siJe
"#="f'&"1As")'"fA&1!s")
#=f'&1As)'fA&1!s)
J#=Jf'&J1AsJ)'JfA&1!sJ)
Program:
,include%iostream.h-
,include%graphics.h-
,include%math.h-
,include%conio.h-
,include%stdlib.h-
class cube.
public7
void drawcube&int "1KL(int 1KL).
int i2
for&i=02i%*2i'').
if&i%#)
line&"1KiL(1KiL("1Ki'1L(1Ki'1L)2
line&"1K0L(1K0L("1K#L(1K#L)2
B
for&i=*2i%M2i'').
if&i%I)
line&"1KiL(1KiL("1Ki'1L(1Ki'1L)2
line&"1K*L(1K*L("1KIL(1KIL)2
B
for&i=02i%*2i'').
line&"1KiL(1KiL("1Ki'*L(1Ki'*L)2
B
B
B2
void main&).
int
i("1KML(1KML("2KML(2KML(J1KML("#KML(#KML(J#KML("*KML(*KML(theta(op(ch(t"(t(tJ(s"(s(sJ("f(f(Jf("((J(siJe
2
int driver=/0T01T2
int mode2
initgraph&5driver(5mode(6c788tc88bgi6)2
cout%%6enter the points on the cube762
cin--"----J2
cout%%6enter the siJe of the edge762
cin--siJe2
"1K0L="1K#L="2
"1K1L="1K2L="'siJe2
"1K*L="1KIL="2
"1KCL="1KHL="'siJe2
1K0L=1K1L=2
1K2L=1K#L='siJe2
1K*L=1KCL=2
1KHL=1KIL='siJe2
J1K1L=J1K2L=J1K#L=J1K0L=J2
J1K*L=J1KCL=J1KHL=J1KIL=J!siJe2
for&i=02i%M2i'').
"2KiL="1KiL'J1KiLD22
2KiL=1KiL'J1KiLD22
B
cube c2
getch&)2
cleardevice&)2
do.
cout%%6menu6%%endl2
cout%%68n 1.Translation8n 2.+otation8n #.=caling8n *.0"it8n62
cout%%6enter the choice762
cin--ch2
switch&ch).
case 17
cout%%6enter the translation vector762
cin--t"--t--tJ2
for&i=02i%M2i'').
"#KiL="1KiL't"2
#KiL=1KiL't2
J#KiL=J1KiL'tJ2
B
for&i=02i%M2i'').
"*KiL="#KiL'J#KiLD22
*KiL=#KiL'J#KiLD22
B
cleardevice&)2
cout%%6before translation62
c.drawcube&"2(2)2
getch&)2
cleardevice&)2
cout%%6after translation62
c.drawcube&"*(*)2
getch&)2
cleardevice&)2
brea$2
case 27
cout%%6enter the rotation angle762
cin--theta2
theta=&thetaA#.1*)D1M02
cout%%6enter the direction6%%endl2
cout%%61.+otation about " a"is6%%endl%%62.+otation about a"is6%%endl%%6#.+otation about J a"is62
cin--op2
if&op==1).
for&i=02i%M2i'').
"#KiL="1KiL2
#KiL=1KiLAcos&theta)!J1KiLAsin&theta)2
J#KiL=1KiLAsin&theta)'J1KiLAcos&theta)2
B
B
else
if&op==2).
for&i=02i%M2i'').
#KiL=1KiL2
"#KiL=J1KiLAcos&theta)!"1KiLAsin&theta)2
"#KiL=J1KiLAsin&theta)'"1KiLAcos&theta)2
B
B
else
if&op==#).
for&i=02i%M2i'').
J#KiL=J1KiL2
"#KiL="1KiLAcos&theta)!1KiLAsin&theta)2
#KiL="1KiLAsin&theta)'1KiLAcos&theta)2
B
B
else
cout%%6enter correct option62
for&i=02i%M2i'').
"*KiL="#KiL'J#KiLD22
*KiL=#KiL'J#KiLD22
B
cleardevice&)2
cout%%6before rotation62
c.drawcube&"2(2)2
getch&)2
cleardevice&)2
cout%%6after rotation62
c.drawcube&"*(*)2
getch&)2
cleardevice&)2
brea$2
case #7
cout%%6enter scaling factor762
cin--s"--s--sJ2
cout%%6enter the reference point762
cin--"f--f--Jf2
for&i=02i%M2i'').
"#KiL="f'&"1KiLAs")'"fA&1!s")2
#KiL=f'&1KiLAs)'fA&1!s)2
J#KiL=Jf'&J1KiLAsJ)'JfA&1!sJ)2
B
for&i=02i%M2i'').
"*KiL="#KiL'J#KiLD22
*KiL=#KiL'J#KiLD22
B
cleardevice&)2
cout%%6before scaling62
c.drawcube&"2(2)2
getch&)2
cleardevice&)2
cout%%6after scaling62
c.drawcube&"*(*)2
getch&)2
brea$2
case *7
e"it&0)2
brea$2
B
B
while&opP=*)2
getch&)2
B
Output:
0nter the point in the cube7 100 100 100
0nter the siJe of the edge7 C0
Tenu
1. translation
2. rotation
#. scaling
*. e"it
0nter the choice71
0nter the translation vector7 C(10(1C
Sefore translation Nfter translation
Result: Thus the program was e"ecuted successfull.
E,-#O-: 5
Date : CO*POS"TE 4D TRA#S)OR*AT"O#
Aim: To appl transformation to #!/imensional shapes in c''.
Algorithm:
1.To composite translate the cube appl formula
"#="1't"
#=1't
J#=J1'tJ
2.To composite rotate the cube appl
"#="12
#=1Acos&theta)!J1Asin&theta)
J#=1Asin&theta)'J1Acos&theta)
#.To composite scale the cube siJe
"#="f'&"1As")'"fA&1!s")
#=f'&1As)'fA&1!s)
J#=Jf'&J1AsJ)'JfA&1!sJ)
Program:
,include%iostream.h-
,include%graphics.h-
,include%math.h-
,include%conio.h-
,include%stdlib.h-
class cube.
public7
void drawcube&int "1KL(int 1KL).
int i2
for&i=02i%*2i'').
if&i%#)
line&"1KiL(1KiL("1Ki'1L(1Ki'1L)2
line&"1K0L(1K0L("1K#L(1K#L)2
B
for&i=*2i%M2i'').
if&i%I)
line&"1KiL(1KiL("1Ki'1L(1Ki'1L)2
line&"1K*L(1K*L("1KIL(1KIL)2
B
for&i=02i%*2i'').
line&"1KiL(1KiL("1Ki'*L(1Ki'*L)2
B
B
B2
void main&).
int
i("1KML(1KML("2KML(2KML(J1KML("#KML(#KML(J#KML("*KML(*KML(theta(theta1("f1(f1(Jf1(op(ch(t"(t(tJ(t"1(t1
(tJ1(s"1(s1(sJ1(s"(s(sJ("f(f(Jf("((J(siJe2
int driver=/0T01T2
int mode2
initgraph&5driver(5mode(6c788tc88bgi6)2
cout%%6enter the points on the cube762
cin--"----J2
cout%%6enter the siJe of the edge762
cin--siJe2
"1K0L="1K#L="2
"1K1L="1K2L="'siJe2
"1K*L="1KIL="2
"1KCL="1KHL="'siJe2
1K0L=1K1L=2
1K2L=1K#L='siJe2
1K*L=1KCL=2
1KHL=1KIL='siJe2
J1K1L=J1K2L=J1K#L=J1K0L=J 2
J1K*L=J1KCL=J1KHL=J1KIL=J!siJe2
for&i=02i%M2i'').
"2KiL="1KiL'J1KiLD22
2KiL=1KiL'J1KiLD22
B
cube c2
getch&)2
cleardevice&)2
do.
cout%%6menu6%%endl2
cout%%68n1.translation8n2.rotation8n#.scaling8n*.e"it8n62
cout%%6enter the choice762
cin--ch2
switch&ch).
case 17
cout%%6enter the first translation vector762
cin--t"--t--tJ2
cout%%68n enter the second translation vector762
cin--t"1--t1--tJ12
cleardevice&)2
cout%%6before translation62
c.drawcube&"2(2)2
getch&)2
for&i=02i%M2i'').
"#KiL="1KiL't"2
#KiL=1KiL't2
J#KiL=J1KiL'tJ2
B
for&i=02i%M2i'').
"*KiL="#KiL'J#KiLD22
*KiL=#KiL'J#KiLD22
B
cleardevice&)2
cout%%6after first translation62
c.drawcube&"*(*)2
getch&)2
for&i=02i%M2i'').
"#KiL="#KiL't"12
#KiL=#KiL't12
J#KiL=J#KiL'tJ12
B
for&i=02i%M2i'').
"*KiL="#KiL'J#KiLD22
*KiL=#KiL'J#KiLD22
B
cleardevice&)2
cout%%6after second translation62
c.drawcube&"*(*)2
getch&)2
cleardevice&)2
brea$2
case 27
cout%%6enter the first rotation angle762
cin--theta2
cout%%6enter the second rotation angle762
cin--theta12
theta=&thetaA#.1*)D1M02
theta1=theta'&theta1A#.1*)D1M02
cout%%6enter the direction6%%endl2
cout%%61.rotation about " a"is6%%endl%%62.rotation about a"is6%%endl%%6#.rotation about J a"is62
cin--op2
cleardevice&)2
cout%%6before rotation62
c.drawcube&"2(2)2
getch&)2
if&op==1).
for&i=02i%M2i'').
"#KiL="1KiL2
#KiL=1KiLAcos&theta)!J1KiLAsin&theta)2
J#KiL=1KiLAsin&theta)'J1KiLAcos&theta)2
B
for&i=02i%M2i'').
"*KiL="#KiL'J#KiLD22
*KiL=#KiL'J#KiLD22
B
cleardevice&)2
cout%%6after first rotation62
c.drawcube&"*(*)2
getch&)2
for&i=02i%M2i'').
"#KiL="1KiL2
#KiL=1KiLAcos&theta1)!J1KiLAsin&theta1)2
J#KiL=1KiLAsin&theta1)'J1KiLAcos&theta1)2
B
for&i=02i%M2i'').
"*KiL="#KiL'J#KiLD22
*KiL=#KiL'J#KiLD22
B
cleardevice&)2
cout%%6after second rotation62
c.drawcube&"*(*)2
getch&)2
B
else
if&op==2).
for&i=02i%M2i'').
#KiL=1KiL2
"#KiL=J1KiLAcos&theta)!"1KiLAsin&theta)2
"#KiL=J1KiLAsin&theta)'"1KiLAcos&theta)2
B
for&i=02i%M2i'').
"*KiL="#KiL'J#KiLD22
*KiL=#KiL'J#KiLD22
B
cleardevice&)2
cout%%6after first rotation62
c.drawcube&"*(*)2
getch&)2
for&i=02i%M2i'').
#KiL=1KiL2
"#KiL=J1KiLAcos&theta1)!"1KiLAsin&theta1)2
"#KiL=J1KiLAsin&theta1)'"1KiLAcos&theta1)2
B
for&i=02i%M2i'').
"*KiL="#KiL'J#KiLD22
*KiL=#KiL'J#KiLD22
B
cleardevice&)2
cout%%6after second rotation62
c.drawcube&"*(*)2
getch&)2
B
else
if&op==#)
.
for&i=02i%M2i'').
J#KiL=J1KiL2
"#KiL="1KiLAcos&theta)!1KiLAsin&theta)2
#KiL="1KiLAsin&theta)'1KiLAcos&theta)2
B
for&i=02i%M2i'').
"*KiL="#KiL'J#KiLD22
*KiL=#KiL'J#KiLD22
B
cleardevice&)2
cout%%6after first rotation62
c.drawcube&"*(*)2
getch&)2
for&i=02i%M2i'').
J#KiL=J1KiL2
"#KiL="1KiLAcos&theta1)!1KiLAsin&theta1)2
#KiL="1KiLAsin&theta1)'1KiLAcos&theta1)2
B
for&i=02i%M2i'').
"*KiL="#KiL'J#KiLD22
*KiL=#KiL'J#KiLD22
B
cleardevice&)2
cout%%6after second rotation62
c.drawcube&"*(*)2
getch&)2
B
else
cout%%6enter correct option62
cleardevice&)2
brea$2
case #7
cout%%6enter the first scaling factor762
cin--s"--s--sJ2
cout%%6enter the second scaling factor762
cin--s"1--s1--sJ12
cout%%6enter the first reference point762
cin--"f--f--Jf2
cout%%6enter the second reference point762
cin--"f1--f1--Jf12
cleardevice&)2
cout%%6before scaling62
c.drawcube&"2(2)2
getch&)2
for&i=02i%M2i'').
"#KiL="f'&"1KiLAs")'"fA&1!s")2
#KiL=f'&1KiLAs)'fA&1!s)2
J#KiL=Jf'&J1KiLAsJ)'JfA&1!sJ)2
B
for&i=02i%M2i'').
"*KiL="#KiL'J#KiLD22
*KiL=#KiL'J#KiLD22
B
cleardevice&)2
cout%%6after first scaling62
c.drawcube&"*(*)2
getch&)2
for&i=02i%M2i'').
"#KiL="f1'&"1KiLAs"As"1)'"f1A&1!s"!s"1)2
#KiL=f1'&1KiLAsAs1)'f1A&1!s!s1)2
J#KiL=Jf1'&J1KiLAsJAsJ1)'Jf1A&1!sJ!sJ1)2
B
for&i=02i%M2i'').
"*KiL="#KiL'J#KiLD22
*KiL=#KiL'J#KiLD22B
cleardevice&)2
cout%%6after second scaling62
c.drawcube&"*(*)2
getch&)2
cleardevice&)2
brea$2
case *7
e"it&0)2
brea$2BB
while&opP=*)2
getch&)2B
Output:
0nter the point in the cube7 100 100 100
0nter the siJe of the edge7 C0
Tenu
1. translation
2. rotation
#. scaling
*. e"it
0nter the choice71
0nter the <irst translation vector7 C(10(1C
0nter the =econd translation vector71C(1C(1C
Sefore translation
Nfter <irst translation
Nfter second translation
Result: Thus the program was e"ecuted successfull.
E,-#O-: 6
Date : 40 D"*E#S"O#A OB7ECTS A#D SCE#ES
Aim:
To create #/ obFects and scenes using blender animation software.
Algorithm:
step 1: Place the cursor to center b pressing shift'= and selecting cursor to center option from the menu.
step (: Ndd an obFect b pressing shift'N and selecting the cube obFect from the pop menu.
step 4: =hape of the obFect can be modified to a human bod b dividing the obFect and e"panding part of
the divided obFect.
step +: Nnimating the human bod done b placing the armature bones in arms and legs of the human
bod.
step .: Sones has to be deformed with the human bod such that arms and legs of the human bod moves
when the bone moves.
step 1: Gsing $e frames( movements of the human bod can be given for each timeline.
Pro!edure:
Slender provides ou with twent ;aers to help organiJe our wor$. 4ou can see which ;aers
are currentl visible from the group of twent buttons in the #/ Eiew window header.
Building the Bod8:
1hange to the front view with 1 9umpad. pressing =pace U Ndd U Tesh U 1ube. N cube will
appear. Press tab( and it will be in 0dit mode with all its vertices selected. 0dit mode is a mode in which
ou can edit the vertices of the mesh.
S default( all vertices are selected for ever new obFect created. ObFect mode is a mode where
vertices cannot be selected or individuall edited. The obFect can be changed onl as a whole. Press tab to
switch between these two modes. This will split each side of the cube in two( creating new vertices and
faces.
:ith our cursor hovering in the #/ window press N to deselect all elements 9ow locate the
=ubdivide button in the Tesh Tools panel and press it once. ?o to right view b pressing # 9umpad. Nnd
select the top two faces of the subdivided cube b right clic$ing the faces with the face selection button
on. <rom modifiers panel select add modifiers and select mirror option. 9ow e"trude the top right two
faces b selecting e"trude region or pressing e.
0"trude b moving the mouse till the needed siJe for the hands. @ere( the both side top right and
left two faces e"trudes as the mirror option is selected. =imilarl( change to bottom view and select the
left two faces in face selection mode and change to front view.
+otate the faces slight to the left direction b pressing + and moving mouse to the left. Nfter the
needed rotate press left mouse button. 9ow select e"trude region and e"trude the leg part where the both
sides are e"truded as the mirror is selected. 1hange to ObFect mode b press tab and clic$ on the Nppl
button of the Tirror modifier.
Ta$e sure ou are in 0dit mode. Tove the cursor to e"actl one Slender Gnit &grid sVuare) above
?usWs bod &leftmost image in ?iving ?us a head). To place the cursor at a specific grid point( position it
near to where ou want it( then press shift's to summon the =nap menu. The 1ursor ?rid entr places
the cursor e"actl on a grid point. 1ursor =election places it e"actl on the selected obFect.
Ndd a new cube with shift's U Ndd U 1ube. =o far( what we have is a rough figure( at best. To
ma$e ?us appear smoother( locate the Todifiers panel in the 0diting conte"t( and add a =ubsurface
modifier. To appl our smoothing effect to ?us( press the =et =mooth button found in the ;in$ and
Taterials panel of the 0diting conte"t. ?us should now appear smooth.
Animating $us:
Rigging
X In obFect mode( set our #/ cursor where ?usWs shoulder is( and press shift's U Ndd U Nrmature.
N rhomboidal obFect will appear( which is a bone of the armature sstem. 0nter 0dit mode. The end( or
tip( of the bone is selected &ellow).
X 9ow in 0dit mode( place the tip of the bone in ?usWs hand b grabbing ? and moving it( &Ndding
the first bone( an elbowless arm). :e donWt need an other bones right now. 4ou should now have one
bone running from the shoulder to the hand area. Ns ou move the tip( ou will notice that the whole bone
gets bigger Y ou reall are scaling up the bone.
X Periodicall loo$ at the ?ingerbread man and armature from man different viewpoints to ma$e
sure the armature is inside the gingerbread man( Fust as bones are inside a human bod.
X =ta in 0dit mode( then move the cursor to where the hip Foint will be and add a new bone shift's
U Ndd U Sone.
X ?rab ? and move the ellow tip of the new bone to the $nee area.
X 9ow Zchain[ a new bone from the $nee to the foot clic$ing in the area of the foot. N new chained
bone will appear automaticall lin$ed with the $nee and ending at the foot. Nnother wa of chaining the
new bone would be to e"trude using the 0 shortcut. This variation creates the new bone and places ou in
grab mode automaticall. =imilarl place the bones on the right side.
Posing
X =elect the armature onl( then select Pose Tode from the Tode menu &Tode menu in the #/
window header) Y or simpl hit 1trl Tab. This option is onl available when an armature is selected.
X The armature will turn blue. 4ou are now in Pose mode. If ou now select a bone it will turn
can( not pin$( and if ou move it &?)( or rotate it &+)( the bod will deform accordinglP
Original position
X Slender remembers the original position of the bones. 4ou can set our armature bac$ b pressing
Nlt+ to clear the bonesW rotation( and Nlt? to clear their location. Nlternativel( the +est Position button
ma be used to temporaril show the original position.
"n9erse :inemati!s
X Inverse \inematics &I\) is where ou actuall define the position of the last bone in the chain(
often called an Zend effector[. Nll the other bones assume an algorithmic position( automaticall
computed b the I\ solver( to $eep the chain without gaps &i.e. I\ will mathematicall solve the chain
positions for us). This allows a much easier and precise positioning of hands and feet using I\.
)orward :inemati!s
X :hile handling bones in Pose mode( notice that the act as rigid( ine"tensible bodies with
spherical Foints at the end. 4ou can grab onl the first bone of a chain and all the others will follow it. Nll
subseVuent bones in the chain cannot be grabbed and moved( ou can onl rotate them( so that the
selected bone rotates with respect to the previous bone in the chain while all the subseVuent bones of the
chain follow its rotation.
X This procedure( called <orward \inematics &<\)( is eas to follow but it ma$es precise location
of the last bone in the chain difficult.
X Ta$e ?us wal$( using <\( b defining four different poses relative to four different stages of a
stride. Slender will do the wor$ of creating a fluid animation.
X <irst( verif that ou are at frame 1 of the timeline. The frame number appears in a numeric field
on the right of the Suttons window header &The current frame numeric field in the Suttons window
header). If it is not set to 1( set it to 1 now.
X 9ow( b rotating onl one bone at a time &+)( weWll raiseGp;eg.; and bend ;o;eg.; bac$wards
while raising Nrm.+a little and lowering Nrm.; a little( as shown in &Our first pose).
X =elect all bones with N. :ith the mouse pointer on the #/ window( press I. N menu pops up
&=toring the pose to the frame). =elect ;oc+ot from this menu. This will get the position and orientation
of all bones and store them as a pose at frame 1. This pose represents ?us in the middle of his stride(
while moving his left leg forward and above the ground.
X 9ow move to frame 11 either b entering the number in the numeric field or b pressing ]. Then
move ?us to a different position( li$e &Our second pose). =tart with clearing the rotation on both arms
using Nlt+ as mentioned earlier. <rom the top view( rotate Nrm.+ slightl forward and Nrm.; slightl
bac$. <inish the pose with his left leg forward and right leg bac$ward( both slightl bent. ?us is wal$ing
in placeP
X =elect all bones again and press I to store this pose at frame11( and select +ot.
X :e now need a third pose at frame 21( with the right leg up( because we are in the middle of the
other half of the stride. This pose is the mirror of the one we defined at frame 1. Therefore( return to
frame 1 and( with all the bones selected( in the Pose menu of the #/ window header( select the1op
1urrent Pose entr( see &Pose menu). 4ou have now copied the current pose to the buffer.
X ?o to frame 21 and paste the pose with thePaste <lipped Pose option in the Pose menu( see &Pose
menu). This will paste the cut pose( e"changing the positions of bones with suffi" Z.;[ with those of
bones with suffi" Z.+[( effectivel flipping itP
The pose is there but it has not been stored etP 4ou must press I U +ot with all bones selected.
X 9ow appl the same procedure to cop the pose at frame 11to frame #1( also flipping it.
X To complete the ccle( we need to cop the pose at frame 1(without flipping it( to frame *1. /o
so b coping it as usual( and b using the Paste Pose entr. 0nd the seVuence b storing the pose with I
U +ot.
Output:
Result:
Thus the #/ obFect was created and animated using the blender software.
E,-#O-: 1;
Date : $E#ERAT"#$ )RACTA "*A$ES
Aim: To draw fractal images in c.
Algorithm:
1.Gse random function to select random number between 0 to 2
2.if random number is 0 ne"t point can be given b
"1 = &"2 ' #20) D 22
1 = &2 ' 0) D 22
#.if random number is 1 ne"t point can be given b
"1 = &"2 ' 0) D 22
1 = &2 ' *M0) D 22
*.if random number is 2 ne"t point can be given b
"1 = &"2 ' H*0) D 22
1 = &2 ' *M0) D 22
Program:
,include %stdio.h-
,include %conio.h-
,include %stdlib.h-
,include %math.h-
,include %graphics.h-
void /raw=ierpins$i&void)2
void main&void)
.
int gd=E?N2
int gm=E?N@I2
initgraph&5gd( 5gm( 688tc88bgi6)2
/raw=ierpins$i&)2
getch&)2
B
void /raw=ierpins$i&void)
.
char /irect2
int iterate2
unsigned int "1( 1( "2( 22
"1 = "2 = #202
1 = 2 = 02
for&iterate = 02 iterate % 100002 iterate'')
.
/irect = random&#)2
if&/irect == 0)
.
"1 = &"2 ' #20) D 22
1 = &2 ' 0) D 22
B
else if&/irect == 1)
.
"1 = &"2 ' 0) D 22
1 = &2 ' *M0) D 22
B
else if&/irect == 2)
.
"1 = &"2 ' H*0) D 22
1 = &2 ' *M0) D 22
B
putpi"el&"1( 1( :@IT0)2
"2 = "12
2 = 12
B
B
Output :
Result:
Thus the program was e"ecuted successfull.