Implementation of Two Dimensional Composite Transformations
Implementation of Two Dimensional Composite Transformations
DESCRIPTION:
A transformation is any operation on a point in space (x, y) that maps the point's coordinates into a new set
of coordinates (x1, y1).The Two Dimensional Composite transformation represent a sequence of
transformations as a single matrix which has the order of operations as Translation, Rotation, Scaling,
Shearing, Reflection.
CODING:
#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;
scanf("%d %d %d %d %d %d",&xa,&ya,&xb,&yb,&xc,&yc);
printf("\n\n The original Image"); /* get the coordinates for the original image*/ line(xa,ya,xb,yb); /*
draw the original image*/
line(xb,yb,xc,yc);
line(xc,yc,xa,ya);
printf("\n\n Enter the value tranlsation factor :"); /* get the translation factor*/ scanf("%d",&tx);
printf("\n\n After Translation "); x1a=xa+tx;
x1b=xb+tx;
x1c=xc+tx;
y1a=ya;
y1b=yb;
y1c=yc;
line(x1c,y1c,x1a,y1a);
delay(1);
printf("\n\n Enter the rotation angle :"); /* get the angle of rotation*/ scanf("%f",&ang);
line(x2b,y2b,x2c,y2c);
line(x2c,y2c,x2a,y2a);
delay(1);
scanf("%f %f",&sx,&sy);
x3a=x2a+sx; /* modify the objects coordinates based on the scale factor*/ y3a=y2a+sy;
x3b=x2b+sx;
y3b=y2b+sy;
x3c=x2c+sx;
y3c=y2c+sy;
else
if(ch==1)
x3a=x3a+shx*y3a;
y4a=y3a;
x3b=x3a+shx*y3a;
y4b=y3b;
x3c=x3a+shx*y3a;
y4c=y3c;
else
{ x4a=x3a;
y3a=y3a+shy*x3a;
x4b=x3b;
y3b=y3b+shy*x3b;
x4c=x3c;
y3c=y3c+shy*x3c;
}
printf("\n\n After Shearing "); /* draw the final object after shearing*/ line(x3a,y3a,x3b,y3b);
line(x3b,y3b,x3c,y3c);
line(x3c,y3c,x3a,y3a);
delay(1);
printf("\n\n Next Operation is Reflection"); t=abs(y3a-y3c); /* calculate the value for reflection*/ x5a=x3a;
x5b=x3b;
x5c=x3c;
y5a=y3a+10+(2*t);
y5b=y3b+10;
y5c=y3c+10;
printf("\n\n After Reflection "); /* the final object after all the transformations*/ line(x5a,y5a,x5b,y5b);
line(x5b,y5b,x5c,y5c);
line(x5c,y5c,x5a,y5a);
getch();
closegraph(); return 0;
OUTPUT:
2D Composite Transformations Enter all coordinates values 213 236 253 321 256 214
After Translation
After Rotation
After Scaling
After Shearing
Enter 0 for x axis and 1 for y axis 1
After Reflection
DESCRIPTION:
Output primitives have geometric and non-geometric attributes. Geometric attributes, such as the character
height, affect the size and shape of a primitive, whereas non-geometric attributes are qualities such as
colour, line style, etc. The output primitives Such as Line, Circle and Ellipse are associated with set of
attributes such as Line (color and Line Style), Cicrle (Color) and Ellipse (Color and Patterns).
CODING:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
int main(void)
char *lname[]={"Solid Line", "Dotted Line", "Center Line", "Dashed Line", "Usebit Line"};
getch();
do{
scanf("%d",&ch);
switch(ch)
case 1:
printf("Attribute: 1.Color 2.Style:\n");
scanf("%d",&ch1);
switch(ch1)
case 1:
y=getmaxy()/2;
for(color=1;color<=maxcolor;color++)
cleardevice();
setcolor(color);
line(100,100,100,300);
sprintf(msg,"Color:%d",color);
outtextxy(x,y,msg);
getch();
closegraph();
break; case 2: