You are on page 1of 2

EXPERIMENT No.

QUE: To perform 2-D Translation Transformation


ALGORITHM:

1. Start
2. Initialize the graphics mode.
3. Construct a 2D object (use Drawpoly()) e.g. (x,y)
4. Translation

a. Get the translation value tx, ty


b. Move the 2d object with tx, ty (x’=x+tx,y’=y+ty)
c. Plot (x’,y’)

5. END Algorithm

PROGRAM:
#include<stdio.h>
#include<graphics.h>
int graDriver=DETECT,graMode;
int n,xs[100],ys[100],i,xshift,yshift;

void DrawFn();
void translate();

void main()
{
printf("Enter number of sides of polygon: ");
scanf("%d",&n);
printf("Enter co-rdinates: x,y for each vertex ");
for(i=0;i<n;i++)
scanf("%d%d",&xs[i],&ys[i]);
printf("Enter distances for translation (in x and y directions): ");
scanf("%d%d",&xshift,&yshift);
initgraph(&graDriver,&graMode,"C:\\TURBOC3\\BGI\\");
cleardevice();
//drawing original polygon in RED color
setcolor(RED);
DrawFn();
//Doing translation
translate();
//drawing translated polygon in BLUE color
setcolor(BLUE);
DrawFn();
getch();
}

void DrawFn()
{
for(i=0;i<n;i++)
{
line(xs[i],ys[i],xs[(i+1)%n],ys[(i+1)%n]);
}
}

void translate()
{
for(i=0;i<n;i++)
{
xs[i]+=xshift;
ys[i]+=yshift;
}
}

OUTPUT:

You might also like