Sunday, November 25, 2012

2 DIMENSIONAL TRANSLATION


2 DIMENSIONAL TRANSLATION

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
int px[10],py[10],tx[10],ty[10];
void disp1();
void disp2();
void translation();
int i,n=0;
void main()
{
   /*reqest auto detection */
   int gdriver = DETECT, gmode, errorcode;


   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "");

   /* read result of initialization */
   errorcode = graphresult();
   /* an error occurred */
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }
   setcolor(getmaxcolor());
   printf("\n\n Enter the no of vertics:");
   scanf("%d",&n );
   printf("\n\nEnter the value for coordinate:");
   for(i=0;i<n;i++)
  {
scanf("%d",&px[i]);
scanf("%d",&py[i]);
  }
  clrscr();
  disp1();
  translation();
  clrscr();
  disp2();
  getch();
  closegraph();
}

void disp1()
{
for(i=0;i<n-1;i++)
line(px[i],py[i],px[i+1],py[i+1]);
line(px[n-1],py[n-1],px[0],py[0]);
getch();
}
void disp2()
{
for(i=0;i<n-1;i++)
line(tx[i],ty[i],tx[i+1],ty[i+1]);
line(tx[n-1],ty[n-1],tx[0],ty[0]);
getch();
}
void translation()
{
int dx,dy;
printf("Enter the translation vector:");
scanf("%d %d",&dx,&dy);
for(i=0;i<n;i++)
 {
 tx[i]=px[i]+dx;
 ty[i]=py[i]+dy;
 }
 }

                                   





















2 DIMENSIONAL TRANSLATION


OUTPUT:-

Enter the number of vertices:3

Enter the coordinate 1: 100 200

Enter the coordinate 2: 200 200

Enter the coordinate 3: 200 200

Enter the translation vector: 50 50














0 comments:

Post a Comment