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 gd = DETECT,gm;
initgraph(&gd,&gm,NULL);
int b[3][3];
int d;
cout<<"Enter value of x1: ";
cin>>b[0][0];
cout<<"Enter value of y1: ";
cin>>b[1][0];
cout<<"Enter value of x2: ";
cin>>b[0][1];
cout<<"Enter value of y2: ";
cin>>b[1][1];
cout<<"Enter value of x3: ";
cin>>b[0][2];
cout<<"Enter value of y3: ";
cin>>b[1][2];
b[2][0] = b[2][1] = b[2][2];
setcolor(RED);
line(b[0][0],b[1][0],b[0][1],b[1][1]);
line(b[0][1],b[1][1],b[0][2],b[1][2]);
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)
initgraph(&gd, &gm, NULL);
initwindow(1000,800);
float a[3][3];
int x1,y1,x2,y2,choice;
cout<<"Enter x1 and y1 coordinates: ";
cin>>a[0][0]>>a[1][0];
cout<<"\nEnter x2 and y2 coordinates: ";
cin>>a[0][1]>>a[1][1];
cout<<"\nEnter x3 and y3 coordinates: ";
cin>>a[0][2]>>a[1][2];
a[2][0] =a[2][1] = a[2][2] = 1;
line(a[0][0],a[1][0],a[0][1],a[1][1]);
line(a[0][1],a[1][1],a[0][2],a[1][2]);
line(a[0][2],a[1][2],a[0][0],a[1][0]);
delay(10000);
cout<<"\n1. Translation \n2. Scaling \n3. Rotation";
cout<<"\nEnter choice: ";
cin>>choice;
switch(choice)
{
case 1:
case 1:
{
float a[3][3],c[3][3];
cout<<"\nEnter value value of tx and ty: ";
cin>>a[0][2]>>a[1][2];
a[0][0] = a[1][1] = a[2][2] = 1;
a[1][0] = a[2][0] = a[0][1] = a[2][1] = 0;
float b[3][3],c[3][3];
b[0][0] = b[1][1] = b[2][2] = 1;
b[0][1] = b[1][0] = b[2][0] = b[2][1] = 0;
cout<<"\nEnter tx and ty: ";
cin>>b[0][2]>>b[1][2];
for(int i = 0; i<3; i++)
{
for(int j = 0; j<3; j++)
@ -47,7 +40,7 @@ int main()
c[i][j] = 0;
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][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;
delay(7000);
}
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;
}