Page 153 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 153

Unit 9: Translation



                     newy=y1-yoffset;                                                             Notes
                     move_object(x1,y1,x2,y2,newx,newy);
                     y1-=yoffset;
                     y2-=yoffset;
                     break;
                     caseALT_X:
                     caseESC:
                     caseCR:
                     closegraph();
                     exit(0);
                     }
                     }
                     }

            9.1 2–Dimensional Translation in C program


            Translation is an easy directly line movement of the object in x and y direction. Transformation
            is refer to transform from one location to another location depends upon their transformation
            it is classified the Scaling, Shearing, Reflection and Rotation see the source code in C coding.
            Program
                     #include <stdio.h>
                     #include <stdlib.h>
                     #include<graphics.h>
                     #include<conio.h>
                     #include<math.h>
                     void draw2d(int,int [],int [],int,int);
                     void main()
                     {
                     int gd = DETECT, gm;
                     int x[20], y[20], tx=0, ty=0, i, fs;
                     initgraph(&gd, &gm,”“);
                     printf(“No of sides:”);
                     scanf(“%d”, &fs);
                     printf(“Co-ordinates :”);
                     for(i=0;i<fs;i++)
                     {
                     printf(“(x%d,y%d)”, i, i);
                     scanf(“%d%d”, &x[i], &y[i]);
                     }
                     draw2d(fs, x, y, tx, ty);
                     printf(“translation (x, y):”);
                     scanf(“%d%d”, &tx, &ty);




                                             LOVELY PROFESSIONAL UNIVERSITY                                   147
   148   149   150   151   152   153   154   155   156   157   158