composite transformation: composite objects are several objects and scripts bundled together exposed...
TRANSCRIPT
Composite Transformation: Composite objects are several objects and scripts bundled together exposed to the application as a single object. There are number of transformations performed on any object. The object undergoes sequence of transformation in series and the points of every transformation become input to the next transformation.
For example, a line can be scaled in the beginning then it is translated to a new position and subsequently rotated about origin. Then such a transformation can be represented by_
x1’, y1’, 1 x1, y1, 1 [Tr1] [Tr2] [Tr3]
x2’, y2’, 1 x2, y2, 1
Where, [Tr1] = [S ] = scaling matrix [Tr2] = [T] = translation matrix [Tr3] = [R] = rotation matrix
In this transformation a line is drawn between the twopoints by using ‘line_draw’ function. • This line is scaled by using [b] matrix the scaling
matrix and the operation of multiplication of [a]*[b] is performed by ‘matmult’ and ‘change’ functions resubstitite [c] matrix into [a] matrix and then line is redrawn by using the same ‘line_draw’ function.
• Then, further the line is translated by using ‘trans’ function and the operation is performed similarly by ‘matmult’ and ‘change’ function. The ‘line_draw’ function draws the line.
• The line is further rotated by an angle of ’25 degree’
using ‘rotate’ function and similar way operation is performed by ‘matmult’ and ‘change’ function.
Composite Transformations:A composite transformation is a sequence oftransformations, one followed by the other. Considerthe matrices and transformations in the following list:
Matrix A Rotate by an angle Matrix B Scale by a factor of sx and sy Matrix C Translate in the x,y direction
FLOWCHART: TO DRAW COMPOSIT OBJECT. Start
float pi=22.0/7.0,l=3,m=2,n=3,a[2][3]={{115,80,1}{140,140,1}},b[20,20],c[20][20];float i,j,k,sum=0.0;double x,y,h=50,v=100,sx=1,sy=2;
float theta=25;double atheta=pi*theta/180.0;
line(a[0][0],a[0][1],a[1][0],a[1][1]);
outtextxy(400,300,”press any key to scale”);
b[0][0]=sx;b[0][1]=0.0;b[0][2]=0.0;b[1][0]=0.0;b[1][1]=sy;b[1][2]=0.0;b[2][0]=0.0;b[2][1]=0.0;b[2][2]=1.0;getch();
for(i=0.0;i<m;++i)
for(k=0;k<l;++k)
for(j=0;j<n;++j)
sum+=(a[i][j]*b[j][k]);
false
true
true
c[i][k]=sum;
false
true
false
Continue…
for(i=0.0;i<m;++i)
for(k=0.0;k<l;++k)
a[i][k]=c[i][k];
false
true
true
false
line(a[0][0],a[0][1],a[1][0],a[1][1]);
outtextxy(400,360,”press any key to translate”);
b[0][0]=1.0;b[0][1]=0.0;b[0][2]=0.0;b[1][0]=0.0;b[1][1]=1.0;b[1][2]=0.0;b[2][0]=h;b[2][1]=v;b[2][2]=1.0;getch();
for(i=0.0;i<m;++i)
for(k=0;k<l;++k)
c[i][k]=sum;
for(j=0;j<n;++j)
sum+=(a[i][j]*b[j][k]);
false
false
false
true
true
true
for(i=0.0;i<m;++i)
for(k=0.0;k<l;++k)
a[i][k]=c[i][k];
false
true
true
false
line(a[0][0],a[0][1],a[1][0],a[1][1]);
outtextxy(400,370,”press any key to rotate”);
x=sin(atheta); y=cos(atheta);
b[0][0]=y;b[0][1]=x;b[0][2]=0.0; b[1][0]=-x;b[1][1]=y;b[1][2]=0.0; b[2][0]=0.0;b[2][1]=0.0;b[2][2]=1.0; getch();
for(i=0.0;i<m;++i)
for(k=0;k<l;++k)
c[i][k]=sum;
for(j=0;j<n;++j)
sum+=(a[i][j]*b[j][k]);
false
false
false
true
true
true
Continue…
for(i=0.0;i<m;++i)
for(k=0.0;k<l;++k)
a[i][k]=c[i][k];
false
true
true
false
line(a[0][0],a[0][1],a[1][0],a[1][1]);
outtextxy(400,380,”press any key to close”);
Output
stop
Continue…
Explanation: Start of program
Define data type, initialize variables
Draw a line according to coordinates
Print this message on given position
a and b are two matrix and c is resultant matrix,h and v are translating factors corresponding to x and y direction increments,sx and sy are scaling factors in x and y direction,theta and atheta are rotation angle
Define Scaling matrix
matrix a and b is multiplied and c holds result
Change the position of line and the value of c is assigned to a
Draw a scaled line ongiven position
Print this message on given position
Define translation matrix
matrix a and b is multiplied and c holds result
connector
Change the position of line and the value of c is assigned to a
Draw a translated line ongiven position
Print this message on given position
x and y are rotation angle
Define rotation matrix
matrix a and b is multiplied and c holds result
Change the position of line and the value of c is assigned to a
Draw a rotated line ongiven position
Print this message on given position
Display a translated, scaled and rotated line on screen.
End of program
Continue…
Program:
/*composite transformation*//*program to scaling,translation,rotate a line about origin*/
//include header files#include<graphics.h>#include<conio.h>#include<math.h>#define pi(22.0/7.0)
int driver,mode; /*data type defined that must be integer type variable*/
/*define variables that is used in program*/float pi=22.0/7.0; float l=3,m=2,n=3; float a[2][3]={{115,80,1},{140,140,1}};float b[20][20],c[20][20];double x,y,h,v,sx,sy;
/*define prototype of functions*/void line_draw(void);void scale(void);void matmult(void);void change(void);void trans(void);void rotate(void);
//main programvoid main(){ float theta; double atheta;
detectgraph(&driver,&mode); /*driver and modes are set*/ initgraph(&driver,&mode,"\\BGI"); /*graphic mode is initialized*/
line_draw(); //calling function call to line_draw function outtextxy(400,350,"press any key to scale"); sx=1,sy=2; /*scaling factor in x,y direction*/
//calling functing scale(); matmult(); change(); line_draw(); outtextxy(400,360,"press any key to translate"); h=50;v=100; /*h and v are x and y direction
increments*/
//calling functions trans(); matmult(); change(); line_draw(); outtextxy(400,370,"press any key to rotate");
/*rotation angle*/ theta=25; atheta=pi*theta/180.0;
x=sin(atheta); y=cos(atheta);
//calling functions rotate(); matmult(); change(); line_draw(); outtextxy(400,380,"press any key to close"); getch(); /*display output*/restorecrtmode(); /*restore the screen to the mode */} /*closing braces*/
/*line function, to draw aline*/void line_draw() { line(a[0][0],a[0][1],a[1][0],a[1][1]);}
/*scale function, to increase the size of line */void scale(){ b[0][0]=sx;b[0][1]=0.0;b[0][2]=0.0; b[1][0]=0.0;b[1][1]=sy;b[1][2]=0.0; b[2][0]=0.0;b[2][1]=0.0;b[2][2]=1.0; getch();}
/*translate function, to change the position of line in x and y direction*/void trans(){ b[0][0]=1.0;b[0][1]=0.0;b[0][2]=0.0; b[1][0]=0.0;b[1][1]=1.0;b[1][2]=0.0; b[2][0]=h;b[2][1]=v;b[2][2]=1.0; getch();}
/*rotate function, to rotate a line by an angle*/void rotate(){ b[0][0]=y;b[0][1]=x;b[0][2]=0.0; b[1][0]=-x;b[1][1]=y;b[1][2]=0.0; b[2][0]=0.0;b[2][1]=0.0;b[2][2]=1.0; getch();}
/*matrix multiplication function*/void matmult(){ float i,j,k,sum; for(i=0.0;i<m;++i) { for(k=0;k<l;++k) {
sum=0.0; for(j=0;j<n;++j) { sum+=(a[i][j]*b[j][k]); }
c[i][k]=sum; } }}
/*change function, to change the position of line*/void change(){ float i,k; for(i=0.0;i<m;++i) { for(k=0.0;k<l;++k) {
a[i][k]=c[i][k]; } }}