Write a program to perform translation

5
EXPERIMENT Objective: - Write a program to perform translation. Software Used: - Turbo c Theory: - To translate an object by a vector v, each homogeneous vector p (written in homogeneous coordinates) would need to be multiplied by thistranslation matrix: As shown below, the multiplication will give the expected result: Program : #include <stdio.h> #include <stdlib.h> #include<graphics.h> #include<conio.h> #include<math.h> void draw2d(int,int [],int [],int,int); void main() { int gd=DETECT, gm; int x[20],y[20],tx=0,ty=0,i,fs;

Transcript of Write a program to perform translation

Page 1: Write a program to perform translation

EXPERIMENT

Objective: - Write a program to perform translation.

Software Used: - Turbo c

Theory: - To translate an object by a vector v, each homogeneous vector p (written in homogeneous coordinates) would need to be multiplied by thistranslation matrix:

As shown below, the multiplication will give the expected result:

Program :

#include <stdio.h>

#include <stdlib.h>

#include<graphics.h>

#include<conio.h>

#include<math.h>

void draw2d(int,int [],int [],int,int);

void main()

{

int gd=DETECT, gm;

int x[20],y[20],tx=0,ty=0,i,fs;

initgraph(&gd,&gm," C:\TURBOC3\BIN");

printf("No of edges : ");

scanf("%d",&fs);

Page 2: Write a program to perform translation

printf("Co-ordinates : ");

for(i=0;i<fs;i++)

{

printf("(x%d,y%d)",i,i);

scanf("%d%d",&x[i],&y[i]);

}

draw2d(fs,x,y,tx,ty);

printf("translation (x,y) : ");

scanf("%d%d",&tx,&ty);

draw2d(fs,x,y,tx,ty);

getch();

}

void draw2d(int fs,int x[20],int y[20],int tx,int ty)

{

int i;

for(i=0;i<fs;i++)

{

if(i!=(fs-1))

line(x[i]+tx,y[i]+ty,x[i+1]+tx,y[i+1]+ty);

else

line(x[i]+tx,y[i]+ty,x[0]+tx,y[0]+ty);

}

}

Page 3: Write a program to perform translation

Output:

Page 4: Write a program to perform translation