2D TRANSLATION AND SCALING


2D TRANSLATION AND SCALING
      AIM:
Program to implement 2D  transformation
      ALGORITHM:

·         Declare the variables and use graphics function

·         Create an image to implement 2D transformation

·         First image translation or repositioning is performed

·         Second image scaling or alter a sign

·         Print the output 2D image






CODINGS:


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
int x[4],y[4];
void translate()
{
                        int i=0,tx,ty;
                        printf("Enter the translate value (tx,ty):\n");
                        scanf("%d%d",&tx,&ty);
                        for(i=0;i<=2;i++)
                        line(x[i]+tx,y[i]+ty,x[i+1]+tx,y[i+1]+ty);
                        getch();
}
void scale()
{
                        int sx,sy,i=0;
                        printf("Enter the scale value (sx,sy):\n");
                        scanf("%d%d",&sx,&sy);
                        for(i=0;i<=2;i++)
                        line(x[i]*sx,y[i]*sy,x[i+1]*sx,y[i+1]*sy);
                        getch();
}
void main()
{
                        int i,j,c;
                        int gd=DETECT,gmode;
                        initgraph(&gd,&gmode,"");
                        printf("Enter the x value:\n");
                        for(i=0;i<=2;i++)
                        scanf("%d",&x[i]);
                        printf("Enter the y value:\n");
                        for(i=0;i<=2;i++)
                        scanf("%d",&y[i]);
                        x[3]=x[0];
                        y[3]=y[0];
                        for(i=0;i<=2;i++)
                        line(x[i],y[i],x[i+1],y[i+1]);
                        printf("1.Translate\n");
                        printf("2.scaling\n");
                        printf("3.Exit\n");
                        printf("Enter the choice:");
                        scanf("%d",&c);
                        switch(c)
                        {
                        case 1:
                                    translate();
                                    break;
                        case 2:
                                    scale();
                                    break;
                        default:
                                    printf("Invalid input\n");
                                    break;
                        }
}




 OUTPUT:

 Enter the x value:
  
   100
    20
    30
 
 Enter the y value:

    50
    80
    60

1.      Translate
2.      Scaling
3.      Exit
   
  Enter the choice:1

  Enter the translate value(tx,ty):

     50
    100




Enter the x value:
  
   100
    20
    30
 
 Enter the y value:

    50
    80
    60

1.      Translate
2.      Scaling
3.      Exit
   
 Enter the choice:2

 Enter the scale value(sx,sy):



      2
      2   





RESULT:

            Thus, the program has been successfully executed & output is verified.



Comments