Tuesday, April 13, 2010

2D Transformation

#include
#include
#include
#include
#define gx getmaxx
void main()
{
 int x1,y1,x2,y2,i,gd=DETECT,gm;
 char d;
 void translation(int,int,int,int);
 void scaling(int,int,int,int);
 void rotation(int,int,int,int);
 clrscr();
 initgraph(&gd,&gm,"c:\\tc\\bgi");
 printf("Enter the end-points of the line:\n");
 scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
 line(x1,y1,x2,y2);

  do
  {
   printf("Enter the type of transfromation:\n");
 printf("\t\t\t1--->Translation\n\t\t\t2--->Scaling\n\t\t\t3--->Rotation\n");
  scanf("%d",&i);
   switch(i)
   {
    case 1: translation(x1,y1,x2,y2);
    break;
    case 2: scaling(x1,y1,x2,y2);
    break;
    case 3: rotation(x1,y1,x2,y2);
    break;
     default : break;
    }
    printf("Do u wanna continue???  'Y' or 'N'\n");
    scanf("%s",d);
  }
  while(d!='n'||d!='N');
   getch();
}


  void translation(int x1,int y1,int x2,int y2)
  {
   int tx,ty;
   printf("Enter the translation factors:\n");
   scanf("%d%d",&tx,&ty);
   x1+=tx;
   y1+=ty;
   x2+=tx;
   y2+=ty;
   printf("The new translated line is:\n");
   line(x1,y1,x2,y2);
  }


  void scaling(int x1,int y1,int x2,int y2)
  {
   int sx,sy;
   printf("Enter the scaling factors:\n");
   scanf("%d%d",&sx,&sy);
   x1*=sx;
   y1*=sy;
   x2*=sx;
   y2*=sy;
   printf("The new scaling line is:\n");
   line(x1,y1,x2,y2);
  }


 void rotation(int x1,int y1,int x2,int y2)
  {
   int a1,a2,b1,b2,th;
   printf("Enter the value for theta:\n");
   scanf("%d",&th);
   a2=(x2*cos(th))-(y2*sin(th));
   b2=(y2*cos(th))+(x2*sin(th));
   printf("The new rotated line is:\n");
   line(x1,y1,a2,b2);
  }

0 comments:

Post a Comment

 
ShareThis

Visitor

Website counter
Copyright 2009 Code's. Powered by Blogger
Blogger Templates created by Deluxe Templates
Wordpress by Wpthemescreator
Blogger Showcase