#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<process.h>
void main()
{
int gd,gm,r,tx,ty,xr,yr,g;
float a[3][3],yref,xref;
float b[3][3];
float sx,sy,x1,y1,x2,y2,x3,y3,x4,y4,x11,y11,x22,y22,x33,y33,x44,y44,
a1,xc,yc,shx,shy;
detectgraph(&gd,&gm);
initgraph(&gd,&gm," ");
// printf("ENTER THE CO-ORDINATES OF TRIANGLE :");
// scanf("%f %f %f %f %f %f",&x1,&y1,&x2,&y2,&x3,&y3);
cleardevice();
setcolor(YELLOW);
line(320,0,320,480);
line(0,240,640,240);
printf("**MAIN MENU**");
printf("\n[1] SCALLING.");
printf("\n[2] TRASLATION.");
printf("\n[3] ROTATION.");
printf("\n[4] REFLECTION ALONG X-AXIS.");
printf("\n[5] REFLECTION ALONG Y-AXIS.");
printf("\n[6] REFLECTION ALONG ORIGION.");
printf("\n[7] SHEARING ALONG X-AXIS.");
printf("\n[8] SHEARING ALONG Y-AXIS.\n");
printf("ENTER CHOICE:");
scanf("%d",&r);
if(r==1)
{
x1=60;y1=40;x2=160;y2=40;x3=110;y3=140;
setcolor(9);
line(320+x1,240-y1,320+x2,240-y2);
//setcolor(5);
line(320+x2,240-y2,320+x3,240-y3);
//setcolor(4);
line(320+x3,240-y3,320+x1,240-y1);
printf("ENTER sx & sy :");
scanf("%f %f",&sx,&sy);
xc=(x1+x2+x3)/3;
yc=(y1+y2+y3)/3;
a[1][1]=sx;
a[2][2]=sy;
a[1][2]=0;
a[1][3]=(-(xc*sx)+xc);
a[2][1]=0;
a[2][3]=(-(yc*sy)+yc);
a[3][1]=a[3][2]=0;
a[3][3]=1;
x11=sx*x1+a[1][3]*1;
y11=sy*y1+a[2][3]*1;
x22=sx*x2+a[1][3]*1;
y22=sy*y2+a[2][3]*1;
x33=sx*x3+a[1][3]*1;
y33=sy*y3+a[2][3]*1;
setcolor(BLUE);
line(320+x11,240-y11,320+x22,240-y22);
//setcolor(2);
line(320+x22,240-y22,320+x33,240-y33);
//setcolor(4);
line(320+x33,240-y33,320+x11,240-y11);
getch();
}
else if(r==2)
{
x1=50;y1=50;x2=150;y2=50;x3=100;y3=150;
setcolor(9);
line(320+x1,240-y1,320+x2,240-y2);
//setcolor(2);
line(320+x2,240-y2,320+x3,240-y3);
//setcolor(4);
line(320+x3,240-y3,320+x1,240-y1);
printf("ENTER tx & ty :");
scanf("%d %d",&tx,&ty);
a[1][1]=a[2][2]=a[3][3]=1;
a[1][2]=a[2][1]=0;
a[3][1]=a[3][2]=0;
a[1][3]=tx;
a[2][3]=ty;
x11=x1+tx;
y11=y1+ty;
x22=x2+tx;
y22=y2+ty;
x33=x3+tx;
y33=y3+ty;
setcolor(BLUE);
line(320+x11,240-y11,320+x22,240-y22);
//setcolor(2);
line(320+x22,240-y22,320+x33,240-y33);
//setcolor(4);
line(320+x33,240-y33,320+x11,240-y11);
}
else if(r==3)
{
x1=50;y1=50;x2=150;y2=50;x3=100;y3=150;
setcolor(9);
line(320+x1,240-y1,320+x2,240-y2);
//setcolor(2);
line(320+x2,240-y2,320+x3,240-y3);
//setcolor(4);
line(320+x3,240-y3,320+x1,240-y1);
printf("ENTER ANGLE :");
scanf("%d",&g);
printf("ENTER xr & yr :");
scanf("%d %d",&xr,&yr);
a1=g*(3.14/180);
b[1][1]=b[2][2]=cos(a1);
b[1][2]=-sin(a1);
b[2][1]=sin(a1);
b[1][3]=-(xr*cos(a1))+(yr*sin(a1))+xr;
b[2][3]=-(xr*sin(a1))-(yr*cos(a1))+yr;
b[3][1]=b[3][2]=0;
b[3][3]=1;
x11=(b[1][1]*x1)+(b[1][2]*y1)+(b[1][3]*1);
y11=(b[2][1]*x1)+(b[2][2]*y1)+(b[2][3]*1);
x22=(b[1][1]*x2)+(b[1][2]*y2)+(b[1][3]*1);
y22=(b[2][1]*x2)+(b[2][2]*y2)+(b[2][3]*1);
x33=(b[1][1]*x3)+(b[1][2]*y3)+(b[1][3]*1);
y33=(b[2][1]*x3)+(b[2][2]*y3)+(b[2][3]*1);
setcolor(BLUE);
line(320+x11,240-y11,320+x22,240-y22);
//setcolor(2);
line(320+x22,240-y22,320+x33,240-y33);
//setcolor(4);
line(320+x33,240-y33,320+x11,240-y11);
}
else if(r==4)
{
x1=50;y1=50;x2=150;y2=50;x3=100;y3=150;
setcolor(9);
line(320+x1,240-y1,320+x2,240-y2);
//setcolor(2);
line(320+x2,240-y2,320+x3,240-y3);
//setcolor(4);
line(320+x3,240-y3,320+x1,240-y1);
getch();
b[1][1]=b[3][3]=1;
b[2][2]=-1;
b[1][2]=b[1][3]=0;
b[2][1]=b[2][3]=0;
b[3][1]=b[3][2]=0;
x11=(b[1][1]*x1)+(b[1][2]*y1)+(b[1][3]*1);
y11=(b[2][1]*x1)+(b[2][2]*y1)+(b[2][3]*1);
x22=(b[1][1]*x2)+(b[1][2]*y2)+(b[1][3]*1);
y22=(b[2][1]*x2)+(b[2][2]*y2)+(b[2][3]*1);
x33=(b[1][1]*x3)+(b[1][2]*y3)+(b[1][3]*1);
y33=(b[2][1]*x3)+(b[2][2]*y3)+(b[2][3]*1);
setcolor(BLUE);
line(320+x11,240-y11,320+x22,240-y22);
// setcolor(2);
line(320+x22,240-y22,320+x33,240-y33);
//setcolor(4);
line(320+x33,240-y33,320+x11,240-y11);
}
else if(r==5)
{
x1=50;y1=50;x2=150;y2=50;x3=100;y3=150;
setcolor(9);
line(320+x1,240-y1,320+x2,240-y2);
//setcolor(2);
line(320+x2,240-y2,320+x3,240-y3);
//setcolor(4);
line(320+x3,240-y3,320+x1,240-y1);
getch();
b[1][1]=-1;
b[2][2]=1;
b[2][2]=1;
b[1][2]=b[1][3]=0;
b[2][1]=b[2][3]=0;
b[3][1]=b[3][2]=0;
x11=(b[1][1]*x1)+(b[1][2]*y1)+(b[1][3]*1);
y11=(b[2][1]*x1)+(b[2][2]*y1)+(b[2][3]*1);
x22=(b[1][1]*x2)+(b[1][2]*y2)+(b[1][3]*1);
y22=(b[2][1]*x2)+(b[2][2]*y2)+(b[2][3]*1);
x33=(b[1][1]*x3)+(b[1][2]*y3)+(b[1][3]*1);
y33=(b[2][1]*x3)+(b[2][2]*y3)+(b[2][3]*1);
setcolor(9);
line(320+x11,240-y11,320+x22,240-y22);
// setcolor(2);
line(320+x22,240-y22,320+x33,240-y33);
//setcolor(4);
line(320+x33,240-y33,320+x11,240-y11);
}
else if(r==6)
{
x1=50;y1=50;x2=150;y2=50;x3=100;y3=150;
setcolor(1);
line(320+x1,240-y1,320+x2,240-y2);
setcolor(2);
line(320+x2,240-y2,320+x3,240-y3);
setcolor(4);
line(320+x3,240-y3,320+x1,240-y1);
getch();
b[1][1]=-1;
b[3][3]=1;
b[2][2]=-1;
b[1][2]=b[1][3]=0;
b[2][1]=b[2][3]=0;
b[3][1]=b[3][2]=0;
x11=(b[1][1]*x1)+(b[1][2]*y1)+(b[1][3]*1);
y11=(b[2][1]*x1)+(b[2][2]*y1)+(b[2][3]*1);
x22=(b[1][1]*x2)+(b[1][2]*y2)+(b[1][3]*1);
y22=(b[2][1]*x2)+(b[2][2]*y2)+(b[2][3]*1);
x33=(b[1][1]*x3)+(b[1][2]*y3)+(b[1][3]*1);
y33=(b[2][1]*x3)+(b[2][2]*y3)+(b[2][3]*1);
setcolor(1);
line(320+x11,240-y11,320+x22,240-y22);
setcolor(2);
line(320+x22,240-y22,320+x33,240-y33);
setcolor(4);
line(320+x33,240-y33,320+x11,240-y11);
}
else if(r==7)
{
x1=0,y1=0,x2=100,y2=0,x3=100,y3=100,x4=0,y4=100;
setcolor(1);
line(320+x1,240-y1,320+x2,240-y2);
setcolor(2);
line(320+x2,240-y2,320+x3,240-y3);
setcolor(4);
line(320+x3,240-y3,320+x4,240-y4);
setcolor(5);
line(320+x4,240-y4,320+x1,240-y1);
printf("ENTER shx :");
scanf("%f",&shx);
printf("ENTER yref :");
scanf("%f",&yref);
b[1][1]=b[2][2]=b[3][3]=1;
b[1][2]=shx;
b[1][3]=-shx*yr;
b[2][1]=b[2][3]=b[3][1]=b[3][2]=0;
x11=x1+shx*(y1-yref);
y11=y1;
x22=x2+shx*(y2-yref);
y22=y2;
x33=x3+shx*(y3-yref);
y33=y3;
x44=x4+shx*(y4-yref);
y44=y4;
setcolor(1);
line(320+x11,240-y11,320+x22,240-y22);
setcolor(2);
line(320+x22,240-y22,320+x33,240-y33);
setcolor(4);
line(320+x33,240-y33,320+x44,240-y44);
setcolor(5);
line(320+x44,240-y44,320+x11,240-y11);
}
else if(r==8)
{
x1=0,y1=0,x2=100,y2=0,x3=100,y3=100,x4=0,y4=100;
setcolor(1);
line(320+x1,240-y1,320+x2,240-y2);
setcolor(2);
line(320+x2,240-y2,320+x3,240-y3);
setcolor(4);
line(320+x3,240-y3,320+x4,240-y4);
setcolor(5);
line(320+x4,240-y4,320+x1,240-y1);
printf("ENTER shy :");
scanf("%f",­);
printf("ENTER xref :");
scanf("%f",&xref);
b[1][1]=b[2][2]=b[3][3]=1;
b[2][1]=shy;
b[2][3]=-shy*xref;
b[1][2]=b[1][3]=b[3][1]=b[3][2]=0;
x11=x1;
y11=y1+shy*(x1-xref);
x22=x2;
y22=y2+shy*(x2-xref);
x33=x3;
y33=y3+shy*(x3-xref);
x44=x4;
y44=y4+shy*(x4-xref);
setcolor(1);
line(320+x11,240-y11,320+x22,240-y22);
setcolor(2);
line(320+x22,240-y22,320+x33,240-y33);
setcolor(4);
line(320+x33,240-y33,320+x44,240-y44);
setcolor(5);
line(320+x44,240-y44,320+x11,240-y11);
}
getch();
}
No comments:
Post a Comment