2d transformations
2d transformations
h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT, gm;
int x1=100, y1=100, x2=200, y2=150;
int choice, tx, ty;
float sx, sy, angle;
switch(choice)
{
case 1:
printf("\nEnter translation factors (tx ty): ");
scanf("%d %d", &tx, &ty);
translate(x1, y1, x2, y2, tx, ty);
break;
case 2:
printf("\nEnter scaling factors (sx sy): ");
scanf("%f %f", &sx, &sy);
scale(x1, y1, x2, y2, sx, sy);
break;
case 3:
printf("\nEnter rotation angle (in degrees): ");
scanf("%f", &angle);
rotate(x1, y1, x2, y2, angle);
break;
default:
printf("\nInvalid choice!");
break;
}
getch();
closegraph();
}
// ----------- Translation -----------
void translate(int x1, int y1, int x2, int y2, int tx, int ty)
{
int gd=DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
outtextxy(10,10,"Translation");
rectangle(x1, y1, x2, y2);
setcolor(RED);
rectangle(x1 + tx, y1 + ty, x2 + tx, y2 + ty);
getch();
closegraph();
}
outtextxy(10,10,"Scaling");
rectangle(x1, y1, x2, y2);
setcolor(RED);
rectangle(x1, y1, x2, y2);
getch();
closegraph();
}
outtextxy(10,10,"Rotation");
setcolor(RED);
line(new_x1, new_y1, new_x2, new_y1);
line(new_x2, new_y1, new_x2, new_y2);
line(new_x2, new_y2, new_x1, new_y2);
line(new_x1, new_y2, new_x1, new_y1);
getch();
closegraph();
}