Monday, 29 December 2014

SHEARING

Program for Shearing

#include <stdio.h>
#include <stdlib.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
void draw2d(int,int [],int [],int,int);
void main()
{
int gd=DETECT,gm;
int x[20],y[20],x1[20],y1[20],tx=0,ty=0,i,fs,a;
initgraph(&gd,&gm,"c:\\TurboC3\\BGI");
printf("No of sides : ");
scanf("%d",&fs);
printf("Co-ordinates : ");
for(i=0;i<fs;i++)
{
printf("(x%d,y%d)",i,i);
scanf("%d%d",&x[i],&y[i]);
}
draw2d(fs,x,y,tx,ty);
printf("translation (x,y) : ");
scanf("%d%d",&tx,&ty);
while(1)
{
clrscr();
cleardevice();
printf("1. X Shear\n\n2. Y Shear\n\n3. Exit\n\n");
draw2d(fs,x,y,0,0);
switch(getche())
{
case '1':
printf("X Shear Value : ");
scanf("%d",&a);
for(i=0;i<fs;i++)
{
x1[i]=x[i]+(a*(y[i]-ty));
y1[i]=y[i];
}
break;
case '2':
printf("Y Shear Value : ");
scanf("%d",&a);
for(i=0;i<fs;i++)
{
x1[i]=y[i];
y1[i]=y[i]+(a*(x[i]-tx));
}
break;
case '3':
closegraph();
exit(0);
}
draw2d(fs,x1,y1,tx,ty);
getch();
}
}
void draw2d(int fs,int x[20],int y[20],int tx,int ty)
{
int i;
for(i=0;i<fs;i++)
{
if(i!=(fs-1))
line(x[i]+tx,y[i]+ty,x[i+1]+tx,y[i+1]+ty);
else
line(x[i]+tx,y[i]+ty,x[0]+tx,y[0]+ty);
}
}
OUTPUT:




No comments:

Post a Comment