Friday, 17 October 2014

Translation Transformation

This Code Is One Of The Most Simplified Codes For Translation Transformation In C++

Functions Used:
  1. getmaxx(); = is used for getting maximum value of the x co ordinate of the output screen.
  2. getmaxy(); = is used for getting maximum value of the y co ordinate of the output screen.
Code:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main()
{
clrscr();
int gd=DETECT,gm,maxx,maxy,midx,midy,x1,y1,x,y,tx,ty;
initgraph(&gd,&gm,"C:\\Turboc3\\BGI");
maxx=getmaxx();
maxy=getmaxy();
midx=maxx/2;
midy=maxy/2;
setcolor(WHITE);
line(midx,0,midx,maxy);
line(0,midy,maxx,midy);
cout<<"enter x co-ordinates of the edges: ";
cin>>x1;
cout<<"enter y co-ordinates of the edges: ";
cin>>y1;
x=midx+x1;
y=midy-y1;
line(midx,midy,x,midy);
line(x,midy,x,y);
line(x,y,midx,y);
line(midx,y,midx,midy);
cout<<"Enter Translation factors:\ntx:";
cin>>tx;
cout<<"ty:";
cin>>ty;
setcolor(RED);
midx=midx+tx;
midy=midy-ty;
x=midx+x1;
y=midy-y1;
line(midx,midy,x,midy);
line(x,midy,x,y);
line(x,y,midx,y);
line(midx,y,midx,midy);
getch();
}

Output:


No comments:

Post a Comment