Page 165 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 165

Unit 10: Shearing



            Rotations around the x, y and z axes are called principal rotations. Rotation around any axis   Notes
            can be performed by taking a rotation around the x axis, followed by a rotation around the y
            axis, and followed by a rotation around the z axis. That is to say, any spatial rotation can be
            decomposed into a combination of principal rotations.
            2D Rotation Program Using C Programming
                     #include<stdio.h>
                     #include<conio.h>
                     #include<graphics.h>
                     #include<process.h>
                     #include<math.h>
                     void Triangle(int x1,int y1,int x2,int y2,int x3,int y3);
                     void Rotate(int x1,int y1,int x2,int y2,int x3,int y3);
                     void main ()
                     {
                     int gd=DETECT,gm;
                     int x1,y1,x2,y2,x3,y3;
                     initgraph(&gd,&gm, “”);
                     printf(“Enter the 1st point for the triangle:”);
                     scanf(“%d%d”,&x1,&y1);
                      printf(“Enter the 2nd point for the triangle:”);
                     scanf(“%d%d”,&x2,&y2);
                      printf(“Enter the 3rd point for the triangle:”);
                     scanf(“%d%d”,&x3,&y3);
                     TriAngle(x1,y1,x2,y2,x3,y3);
                     getch();
                     cleardevice();
                     Rotate(x1,y1,x2,y2,x3,y3);
                     setcolor(1);
                     TriAngle(x1,y1,x2,y2,x3,y3);
                     getch();
                     }
                     void TriAngle(int x1,int y1,int x2,int y2,int x3,int y3)
                     {
                     line(x1,y1,x2,y2);
                     line(x2,y2,x3,y3);
                     line(x3,y3,x1,y1);
                     }
                     void Rotate(int x1,int y1,int x2,int y2,int x3,int y3)
                     {
                     int x,y,a1,b1,a2,b2,a3,b3,p=x2,q=y2;
                     float Angle;
                     printf(“Enter the angle for rotation:”);



                                             LOVELY PROFESSIONAL UNIVERSITY                                   159
   160   161   162   163   164   165   166   167   168   169   170