COMPOSITE 2D TRANSFORMATION
code:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
int xa,xb,xc,ya,yb,yc,y1a,y1b,y1c,x1a,x1b,x1c,x2a,x2b,x2c,y2a,y2b,y2c;
int x3a,x3b,x3c,y3a,y3b,y3c,x4a,x4b,x4c,y4a,y4b,y4c,x5a,x5b,x5c,y5a,y5b,y5c;
int tx,shx,t,ch,a,ty;
float ang,theta,sx,sy;
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode,"c:\\turboc3\\bgi");
printf("Enter all coordinates values :");
scanf("%d %d %d %d %d %d",&xa,&ya,&xb,&yb,&xc,&yc);
setcolor(GREEN);
line(xa,ya,xb,yb); /* draw the original image*/
line(xb,yb,xc,yc);
line(xc,yc,xa,ya);
printf("Enter the value tranlsation factor :"); /* get the translation factor*/
scanf("%d",&tx);
printf("Enter ty:");
scanf("%d",&ty);
x1a=xa+tx;
x1b=xb+tx;
x1c=xc+tx;
y1a=ya+ty;
y1b=yb+ty;
y1c=yc+ty;
setcolor(RED);
line(x1a,y1a,x1b,y1b);
line(x1b,y1b,x1c,y1c);
line(x1c,y1c,x1a,y1a);
delay(1);
printf("Next Operation is Rotation");
printf("Enter the rotation angle :");
scanf("%f",&ang);
theta=((ang*3.14)/180);
x2a=x1a*cos(theta)-y1a*sin(theta);
y2a=x1a*sin(theta)+y1a*cos(theta);
x2b=x1b*cos(theta)-y1b*sin(theta);
y2b=x1b*sin(theta)+y1b*cos(theta);
x2c=x1c*cos(theta)-y1c*sin(theta);
y2c=x1c*sin(theta)+y1c*cos(theta);
setcolor(YELLOW);
line(x2a,y2a,x2b,y2b);
line(x2b,y2b,x2c,y2c);
line(x2c,y2c,x2a,y2a);
delay(1);
printf("Next Operation is Scaling");
printf("Enter the Scale factor:");
scanf("%f %f",&sx,&sy);
x3a=x2a+sx;
y3a=y2a+sy;
x3b=x2b+sx;
y3b=y2b+sy;
x3c=x2c+sx;
y3c=y2c+sy;
setcolor(CYAN);
line(x3a,y3a,x3b,y3b);
line(x3b,y3b,x3c,y3c);
line(x3c,y3c,x3a,y3a);
delay(1);
printf("Next Operation is Reflection");
printf("Enter 1 for x and 2 for y:");
scanf("%d",&a);
switch(a){
case 1:
setcolor(GREEN);
line(getmaxx() - xa, ya,
getmaxx() - xb, yb);
line(getmaxx() - xb, yb,
getmaxx() - xc, yc);
line(getmaxx() - xc, yc,
getmaxx() - xa, ya);
break;
case 2:
setcolor(BROWN);
line(xa, getmaxy() - ya, xb,
getmaxy() - yb);
line(xb, getmaxy() - yb, xc,
getmaxy() - yc);
line(xc, getmaxy() - yc, xa,
getmaxy() - ya);
getch();
break;
default:
printf("Enter valid direction\n");
}
getch();
closegraph();
return 0;
}
output:
Comments
Post a Comment