Amazon banner

Friday, 17 August 2012

C PROGRAM TO DEMONSTRATE TRANSLATION TRANSFORMATION

/* C PROGRAM TO DEMONSTRATE TRANSLATION TRANSFORMATION*/

/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
void main()
{
int poly[30],a[9][3],b[3][3],c[9][3];
int x,y,p,i,j,k;
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C:/TC/BGI");
setcolor(1);
setbkcolor(15);
setfillstyle(6,3);
printf("\n Enter number of points : ");
scanf("%d",&p);
j=0;
for(i=0;i<p*2;i+=2)
{
printf("\n Enter co-ordinate point x%d and y%d : ",j+1,j+1);

scanf("%d",&poly[i]);
scanf("%d",&poly[i+1]);
j++;
}
poly[p*2]=poly[0];
poly[p*2+1]=poly[1];

fillpoly(p+1,poly);
putpixel(150,150,RED);

printf("\n Enter Translation factor x and y");
scanf("%d%d",&x,&y);

j=0;
for(i=0;i<p;i++)
{
 a[i][0]=poly[j];
 a[i][1]=poly[++j];
 a[i][2]=1;
 ++j;
}

for(i=0;i<3;i++)
{
 for(j=0;j<3;j++)
 {
   b[i][j]=0;
   if(i==j)
   b[i][j]=1;
 }
}
b[2][0]=x;
b[2][1]=y;



for(i=0;i<p;i++)
{

   for(j=0;j<3;j++)
   {
   c[i][j]=0;
     for(k=0;k<3;k++)
     {
 c[i][j]=c[i][j]+a[i][k]*b[k][j];
     }
   }

 }
printf("\n\n\n\n\n\t After scaling : ");

for(i=0;i<p;i++)
{
printf("\n");
for(j=0;j<3;j++)
{
printf("\t %d",c[i][j]);
}
}


for(i=0,j=0;i<p;i++,j+=2)
{
poly[j]  =c[i][0];
poly[j+1]=c[i][1];
}
poly[j]  =poly[0];
poly[j+1]=poly[1];

setfillstyle(9,2);
fillpoly(p+1,poly);

getch();
closegraph();
}



No comments:

Post a Comment