0% found this document useful (0 votes)
93 views11 pages

Implementation of Two Dimensional Composite Transformations

The document describes the coding implementation of two-dimensional composite transformations and line, circle, and ellipse attributes in graphics programming. The coding shows how to apply a series of transformations (translation, rotation, scaling, shearing, reflection) to an object and how to manipulate attributes like color, line style, and patterns for different graphics primitives. Sample input/output is also provided.

Uploaded by

vasanthi2014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views11 pages

Implementation of Two Dimensional Composite Transformations

The document describes the coding implementation of two-dimensional composite transformations and line, circle, and ellipse attributes in graphics programming. The coding shows how to apply a series of transformations (translation, rotation, scaling, shearing, reflection) to an object and how to manipulate attributes like color, line style, and patterns for different graphics primitives. Sample input/output is also provided.

Uploaded by

vasanthi2014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

5.

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 <graphics.h> /* include the necessary header files*/

#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,shy;

float ang,theta,sx,sy; int main(void)

int gdriver = DETECT, gmode, errorcode;

initgraph(&gdriver, &gmode,"C:\\TC\\BGI"); /* request for auto detection*/ printf("\n\t\t\t 2D Composite


Transformations");

printf("\n\n Enter all coordinates values :");

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(x1a,y1a,x1b,y1b); /* image after translation*/ line(x1b,y1b,x1c,y1c);

line(x1c,y1c,x1a,y1a);

delay(1);

printf("\n\n Next Operation is Rotation");

printf("\n\n Enter the rotation angle :"); /* get the angle of rotation*/ scanf("%f",&ang);

theta=((ang*3.14)/180); /* convert the angle*/ 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);

printf("\n\n After Rotation "); /* the rotated object*/ line(x2a,y2a,x2b,y2b);

line(x2b,y2b,x2c,y2c);

line(x2c,y2c,x2a,y2a);

delay(1);

printf("\n\n Next Operation is Scaling"); /* get the scale factor*/

printf("\n\n Enter the Scale factor :");

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;

printf("\n\n After Scaling "); line(x3a,y3a,x3b,y3b); line(x3b,y3b,x3c,y3c); line(x3c,y3c,x3a,y3a); delay(1);

printf("\n\n Next Operation is Shearing");


printf("\n\n Enter 1 for x-axis \n 2 for y-axis: "); /* get the choice of shearing in the x or y axis*/
scanf("%d",&ch);

if(ch==1) /* get the shear value*/

printf("\n\n Enter the x-SHEAR (^.^) Value: "); scanf("%d",&shx);

else

printf("\n\n Enter the y-SHEAR (^.^) Value: "); scanf("%d",&shy);

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

The original Image


Enter the value translation vector 32

After Translation

Next Operation is Rotation

Enter the rotation angle 20

After Rotation

Next Operation is Scaling


Enter the scale factor 10 5

After Scaling

Next Operation is Shearing

Enter 0 for x axis and 1 for y axis 0

Enter the x-shear value 1

After Shearing
Enter 0 for x axis and 1 for y axis 1

Enter the y-shear value 1

Next Operation is Reflection

After Reflection

6. IMPLEMENTATION OF LINE, CIRCLE AND ELLIPSE ATTRIBUTES

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<graphics.h> /* include the necessary header files*/

#include<stdlib.h>

#include<stdio.h>

#include<conio.h>

int main(void)

/* select a driver and mode that supports */ /* multiple drawing colors.*/

int gdriver=EGA,DETECT,gmode=EGAHI,errorcode; int color,maxcolor,x,y,s,ch,ch1,ch2,i;

int midx,midy; int radius=100;

int xradius=100,yradius=50; char msg[80];

char *lname[]={"Solid Line", "Dotted Line", "Center Line", "Dashed Line", "Usebit Line"};

/* initialize graphics and local variables */ initgraph(&gdriver,&gmode,"c:\\tc\\bgi");


/* read result of initialization */ errorcode=graphresult();

if (errorcode!=grOk) /* an error occurred */

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1); /* terminate with an error code */

do{

printf("\n1.Line\n2.Circle\n3.Ellipse\n"); /* get the user choice*/

printf("\nEnter Your choice\n");

scanf("%d",&ch);

switch(ch)

case 1:
printf("Attribute: 1.Color 2.Style:\n");

scanf("%d",&ch1);

switch(ch1)

case 1:

maxcolor=getmaxcolor(); /* use predefined methods to change the color*/ x=getmaxx()/2;

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:

You might also like