Amazon banner

Thursday 16 August 2012

C PROGRAM TO DEMONSTRATE REFLECTION TRANSFORMATION ABOUT X-AXIS, Y-AXIS AND ORIGIN


/* C PROGRAM TO DEMONSTRATE REFLECTION TRANSFORMATION ABOUT X-AXIS, Y-AXIS AND ORIGIN*/

/* 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],poly2[30];
int x,y,p,i,j,k,xc,yc;
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C:/TC/BGI");
xc=getmaxx()/2;
yc=getmaxy()/2;

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 cordinate 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];



for(i=0;i<p*2;i+=2)
{
poly2[i]=xc+poly[i];
poly2[i+1]=yc-poly[i+1];

}
poly2[p*2]=poly2[0];
poly2[p*2+1]=poly2[1];

fillpoly(p+1,poly2);


line(0,yc,xc*2,yc);
line(xc,0,xc,yc*2);


printf("\n Reflection about : \n 1. x axis\n 2. y axis\n 3. origin\n enter choice : ");
scanf("%d",&x);

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

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

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

}
else if(x==3)
{
    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][2]=1;

}

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 Reflection : ");


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

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

getch();
closegraph();
}





1 comment:

  1. output of the reflection about the x axis and y axis is same.what could be the problem

    ReplyDelete