Translate A Polygon in 2-D

09:22 0 Comments A+ a-

PROGRAM:



#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<math.h>
#include<graphics.h>
void main()
{
clrscr();
int gd=DETECT,gm,x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,tx,ty;
initgraph(&gd,&gm,"c:\\tc\\bgi");
cout<<"Enter the value of x1 & y1: ";
cin>>x1>>y1;
cout<<"Enter the value of x2 & y2: ";
cin>>x2>>y2;
cout<<"Enter the value of x3 & y3: ";
cin>>x3>>y3;
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
cout<<"Enter the translation in x and y direction: ";
cin>>tx>>ty;
x4=x1+tx ;
y4=y1+ty ;
x5=x2+tx ;
y5=y2+ty ;
x6=x3+tx ;
y6=y3+ty ;
line(x4,y4,x5,y5);
line(x5,y5,x6,y6);
line(x6,y6,x4,y4);
delay(100);
//closegraph();
getch();
}