transformation code translation error fixed

This commit is contained in:
Tanmay 2023-11-28 23:39:20 +05:30
parent 22cf98a790
commit c8574f03fa

View File

@ -6,40 +6,33 @@ using namespace std;
int main() int main()
{ {
int gd = DETECT,gm; int gd = DETECT,gm;
initgraph(&gd,&gm,NULL); initgraph(&gd, &gm, NULL);
int b[3][3]; initwindow(1000,800);
int d; float a[3][3];
cout<<"Enter value of x1: "; int x1,y1,x2,y2,choice;
cin>>b[0][0]; cout<<"Enter x1 and y1 coordinates: ";
cout<<"Enter value of y1: "; cin>>a[0][0]>>a[1][0];
cin>>b[1][0]; cout<<"\nEnter x2 and y2 coordinates: ";
cout<<"Enter value of x2: "; cin>>a[0][1]>>a[1][1];
cin>>b[0][1]; cout<<"\nEnter x3 and y3 coordinates: ";
cout<<"Enter value of y2: "; cin>>a[0][2]>>a[1][2];
cin>>b[1][1]; a[2][0] =a[2][1] = a[2][2] = 1;
cout<<"Enter value of x3: "; line(a[0][0],a[1][0],a[0][1],a[1][1]);
cin>>b[0][2]; line(a[0][1],a[1][1],a[0][2],a[1][2]);
cout<<"Enter value of y3: "; line(a[0][2],a[1][2],a[0][0],a[1][0]);
cin>>b[1][2]; delay(10000);
b[2][0] = b[2][1] = b[2][2]; cout<<"\n1. Translation \n2. Scaling \n3. Rotation";
setcolor(RED); cout<<"\nEnter choice: ";
line(b[0][0],b[1][0],b[0][1],b[1][1]); cin>>choice;
line(b[0][1],b[1][1],b[0][2],b[1][2]); switch(choice)
line(b[0][2],b[1][2],b[0][0],b[1][0]);
delay(5000);
cout<<"\nYour Choices Are!! \n";
cout<<"1. Translation: \n2. Scaling: \n3. Rotation: ";
cout<<"\nEnter your choice: ";
cin>>d;
switch(d)
{ {
case 1: case 1:
{ {
float a[3][3],c[3][3]; float b[3][3],c[3][3];
cout<<"\nEnter value value of tx and ty: "; b[0][0] = b[1][1] = b[2][2] = 1;
cin>>a[0][2]>>a[1][2]; b[0][1] = b[1][0] = b[2][0] = b[2][1] = 0;
a[0][0] = a[1][1] = a[2][2] = 1; cout<<"\nEnter tx and ty: ";
a[1][0] = a[2][0] = a[0][1] = a[2][1] = 0; cin>>b[0][2]>>b[1][2];
for(int i = 0; i<3; i++) for(int i = 0; i<3; i++)
{ {
for(int j = 0; j<3; j++) for(int j = 0; j<3; j++)
@ -47,7 +40,7 @@ int main()
c[i][j] = 0; c[i][j] = 0;
for(int k = 0; k<3; k++) for(int k = 0; k<3; k++)
{ {
c[i][j]+=a[i][k]*b[k][j]; c[i][j] += b[i][k]*a[k][j];
} }
} }
} }
@ -55,17 +48,17 @@ int main()
line(c[0][0],c[1][0],c[0][1],c[1][1]); line(c[0][0],c[1][0],c[0][1],c[1][1]);
line(c[0][1],c[1][1],c[0][2],c[1][2]); line(c[0][1],c[1][1],c[0][2],c[1][2]);
line(c[0][2],c[1][2],c[0][0],c[1][0]); line(c[0][2],c[1][2],c[0][0],c[1][0]);
delay(5000); delay(7000);
break;
} }
case 2: break;
case 2:
{ {
float sx,sy; float b[3][3],c[3][3];
float a[3][3],c[3][3]; b[0][1] = b[0][2] = b[1][0] = b[1][2] = b[2][0] = b[2][1] = 0;
cout<<"\nEnter value value of sx and sy: "; b[2][2] = 1;
cin>>a[0][0]>>a[1][1]; cout<<"\nEnter sx and sy: ";
a[2][2] = 1; cin>>b[0][0]>>b[1][1];
a[0][1] = a[0][2] = a[1][0] = a[1][2] = a[2][0] = a[2][1] = 0;
for(int i = 0; i<3; i++) for(int i = 0; i<3; i++)
{ {
for(int j = 0; j<3; j++) for(int j = 0; j<3; j++)
@ -73,7 +66,7 @@ int main()
c[i][j] = 0; c[i][j] = 0;
for(int k = 0; k<3; k++) for(int k = 0; k<3; k++)
{ {
c[i][j]+=a[i][k]*b[k][j]; c[i][j] += b[i][k]*a[k][j];
} }
} }
} }
@ -81,22 +74,23 @@ int main()
line(c[0][0],c[1][0],c[0][1],c[1][1]); line(c[0][0],c[1][0],c[0][1],c[1][1]);
line(c[0][1],c[1][1],c[0][2],c[1][2]); line(c[0][1],c[1][1],c[0][2],c[1][2]);
line(c[0][2],c[1][2],c[0][0],c[1][0]); line(c[0][2],c[1][2],c[0][0],c[1][0]);
delay(5000); delay(7000);
break; }
} break;
case 3:
{ case 3:
float z, A; {
float a[3][3]; float b[3][3],c[3][3];
float c[3][3]; float z;
cout<<"\nEnter the angle: "; cout<<"\nEnter angle: ";
cin>>z; cin>>z;
A = (z*3.14)/180; float ang = (z*3.14)/180;
a[2][2] = 1; b[0][2] = b[1][2] = b[2][0] = b[2][1] = 0;
a[0][2] = a[1][2] = a[2][0] = a[2][1] = 0; b[2][2] = 1;
a[0][0] = a[1][1] = cos(A); b[0][0] = cos(ang);
a[0][1] = sin(A); b[0][1] = sin(ang);
a[1][0] = (-sin(A)); b[1][0] = -(sin(ang));
b[1][1] = cos(ang);
for(int i = 0; i<3; i++) for(int i = 0; i<3; i++)
{ {
for(int j = 0; j<3; j++) for(int j = 0; j<3; j++)
@ -104,7 +98,7 @@ int main()
c[i][j] = 0; c[i][j] = 0;
for(int k = 0; k<3; k++) for(int k = 0; k<3; k++)
{ {
c[i][j]+=a[i][k]*b[k][j]; c[i][j] += b[i][k]*a[k][j];
} }
} }
} }
@ -112,13 +106,9 @@ int main()
line(c[0][0],c[1][0],c[0][1],c[1][1]); line(c[0][0],c[1][0],c[0][1],c[1][1]);
line(c[0][1],c[1][1],c[0][2],c[1][2]); line(c[0][1],c[1][1],c[0][2],c[1][2]);
line(c[0][2],c[1][2],c[0][0],c[1][0]); line(c[0][2],c[1][2],c[0][0],c[1][0]);
delay(5000); delay(7000);
break; }
}
default:
cout<<"\nEnter valid choice!!";
break;
} }
closegraph();
return 0; return 0;
} }