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,70 +48,67 @@ 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:
{
float sx,sy;
float a[3][3],c[3][3];
cout<<"\nEnter value value of sx and sy: ";
cin>>a[0][0]>>a[1][1];
a[2][2] = 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 j = 0; j<3; j++)
{
c[i][j] = 0;
for(int k = 0; k<3; k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
}
}
setcolor(BLUE);
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][2],c[1][2],c[0][0],c[1][0]);
delay(5000);
break;
}
case 3:
{
float z, A;
float a[3][3];
float c[3][3];
cout<<"\nEnter the angle: ";
cin>>z;
A = (z*3.14)/180;
a[2][2] = 1;
a[0][2] = a[1][2] = a[2][0] = a[2][1] = 0;
a[0][0] = a[1][1] = cos(A);
a[0][1] = sin(A);
a[1][0] = (-sin(A));
for(int i = 0; i<3; i++)
{
for(int j = 0; j<3; j++)
{
c[i][j] = 0;
for(int k = 0; k<3; k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
}
}
setcolor(BLUE);
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][2],c[1][2],c[0][0],c[1][0]);
delay(5000);
break;
}
default:
cout<<"\nEnter valid choice!!";
break; break;
case 2:
{
float b[3][3],c[3][3];
b[0][1] = b[0][2] = b[1][0] = b[1][2] = b[2][0] = b[2][1] = 0;
b[2][2] = 1;
cout<<"\nEnter sx and sy: ";
cin>>b[0][0]>>b[1][1];
for(int i = 0; i<3; i++)
{
for(int j = 0; j<3; j++)
{
c[i][j] = 0;
for(int k = 0; k<3; k++)
{
c[i][j] += b[i][k]*a[k][j];
} }
}
}
setcolor(BLUE);
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][2],c[1][2],c[0][0],c[1][0]);
delay(7000);
}
break;
case 3:
{
float b[3][3],c[3][3];
float z;
cout<<"\nEnter angle: ";
cin>>z;
float ang = (z*3.14)/180;
b[0][2] = b[1][2] = b[2][0] = b[2][1] = 0;
b[2][2] = 1;
b[0][0] = cos(ang);
b[0][1] = sin(ang);
b[1][0] = -(sin(ang));
b[1][1] = cos(ang);
for(int i = 0; i<3; i++)
{
for(int j = 0; j<3; j++)
{
c[i][j] = 0;
for(int k = 0; k<3; k++)
{
c[i][j] += b[i][k]*a[k][j];
}
}
}
setcolor(BLUE);
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][2],c[1][2],c[0][0],c[1][0]);
delay(7000);
}
}
closegraph();
return 0; return 0;
} }