Sunday, November 25, 2012

2 DIMENSIONAL SCALING


2 DIMENSIONAL SCALING

#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
int px[10],py[10],tx[10],ty[10];
void disp1();
void disp2();
void scaling();
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();
  scaling();
  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 scaling()
{
int sx,sy;
printf("Enter the scaling vector:");
scanf("%d %d",&sx,&sy);
for(i=0;i<n;i++)
            {
                        tx[i]=px[i]*sx;
 ty[i]=py[i]*sy;
 }
 }

























                                    2-DIMENSIONAL SCALING


OUTPUT:


Enter the number of vertices: 3
Enter the x and y coordinates : 100
150
150
150
150
100
Enter scale factors (2 values ) :
2
2





0 comments:

Post a Comment