Program for shearing and translation.

#include stdio.h
#include conio.h
#include graphics.h
#include math.h

void shearing();
void translation();
void display();

int ax[10],ay[10],n;
void main()
{
int i,gd,gm=DETECT,ch;
clrscr();
printf("Enter the number of vertices in the polygon\t");
scanf("%d",&n);
printf("\nEnter the co-ordinates of the vertices");
for(i=0;i
{
printf("\nEnter the x cordinate and y cordinate of point %d\t",i+1);
scanf("%d %d",&ax[i],&ay[i]);
}
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\bgi");
display();
do
{
printf("\nEnter 1-Shearing 2-Translation 3-Exit\n");
printf("Enter your choice\t");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
shearing();
break;
}
case 2:
{
translation();
break;
}
case 3:
{
exit();
break;
}
}
}while(ch!=4);
getch();
closegraph();
}

void display()
{
int i;
clrscr();
for(i=0;i<(n-1);i++)
{
line(ax[i],ay[i],ax[i+1],ay[i+1]);
}
line(ax[n-1],ay[n-1],ax[0],ay[0]);
}


void shearing()
{
int ch,i,shx,shy;
printf("\nEnter the type of shearing(1-x shear 2-y shear\t");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("\nEnter the shearing value\t");
scanf("%d",&shx);
for(i=0;i
{
ax[i]=ax[i]+(ay[i]*shx);
}
break;
}
case 2:
{
printf("\nEnter the shearing value\t");
scanf("%d",&shy);
for(i=0;i
{
ay[i]=ax[i]*shy+ay[i];
}
break;
}

}
display();
}

void translation()
{
int tx,ty,i;
printf("\nEnter the amount of translation(Enter 0 for no translation)");
scanf("%d %d",&tx,&ty);
for(i=0;i
{
ax[i]=ax[i]+tx;
ay[i]=ay[i]+ty;
}
display();
}

No comments:

Post a Comment