Dark Mode
Image

Rotation

It is a process of changing the angle of the object. Rotation can be clockwise or anticlockwise. For rotation, we have to specify the angle of rotation and rotation point. Rotation point is also called a pivot point. It is print about which object is rotated.

Types of Rotation:

  1. Anticlockwise
  2. Counterclockwise

The positive value of the pivot point (rotation angle) rotates an object in a counter-clockwise (anti-clockwise) direction.

The negative value of the pivot point (rotation angle) rotates an object in a clockwise direction.

5.6M

916

Polymorphism in Java | Dynamic Method Dispatch

When the object is rotated, then every point of the object is rotated by the same angle.

Straight Line: Straight Line is rotated by the endpoints with the same angle and redrawing the line between new endpoints.

Polygon: Polygon is rotated by shifting every vertex using the same rotational angle.

Curved Lines: Curved Lines are rotated by repositioning of all points and drawing of the curve at new positions.

Circle: It can be obtained by center position by the specified angle.

Ellipse: Its rotation can be obtained by rotating major and minor axis of an ellipse by the desired angle.

Rotation
Rotation

Matrix for rotation is a clockwise direction.

Rotation

Matrix for rotation is an anticlockwise direction.

Rotation

Matrix for homogeneous co-ordinate rotation (clockwise)

Rotation

Matrix for homogeneous co-ordinate rotation (anticlockwise)

Rotation

Rotation about an arbitrary point: If we want to rotate an object or point about an arbitrary point, first of all, we translate the point about which we want to rotate to the origin. Then rotate point or object about the origin, and at the end, we again translate it to the original place. We get rotation about an arbitrary point.

Example: The point (x, y) is to be rotated

The (xc yc) is a point about which counterclockwise rotation is done

Step1: Translate point (xc yc) to origin

Rotation

Step2: Rotation of (x, y) about the origin

Rotation

Step3: Translation of center of rotation back to its original position

Rotation
Rotation

Example1: Prove that 2D rotations about the origin are commutative i.e. R1 R2=R2 R1.

Solution: R1 and R2are rotation matrices

Rotation

Example2: Rotate a line CD whose endpoints are (3, 4) and (12, 15) about origin through a 45° anticlockwise direction.

Solution: The point C (3, 4)

Rotation
Rotation
Rotation

Example3: Rotate line AB whose endpoints are A (2, 5) and B (6, 12) about origin through a 30° clockwise direction.

Solution: For rotation in the clockwise direction. The matrix is

Rotation

Step1: Rotation of point A (2, 5). Take angle 30°

Rotation

Step2: Rotation of point B (6, 12)

Rotation
Rotation

Program to rotate a line:

  1. #include<stdio.h>  
  2. #include<graphics.h>  
  3. #include<math.h>  
  4. int main()  
  5. {  
  6.     intgd=0,gm,x1,y1,x2,y2;  
  7.     double s,c, angle;  
  8.     initgraph(&gd, &gm, "C:\\TC\\BGI");  
  9.     setcolor(RED);  
  10.     printf("Enter coordinates of line: ");  
  11.     scanf("%d%d%d%d",&x1,&y1,&x2,&y2);  
  12.     cleardevice();  
  13.     setbkcolor(WHITE);  
  14.     line(x1,y1,x2,y2);  
  15.     getch();  
  16.     setbkcolor(BLACK);  
  17.     printf("Enter rotation angle: ");  
  18.     scanf("%lf", &angle);  
  19.     setbkcolor(WHITE);  
  20.     c = cos(angle *3.14/180);  
  21.     s = sin(angle *3.14/180);  
  22.     x1 = floor(x1 * c + y1 * s);  
  23.     y1 = floor(-x1 * s + y1 * c);  
  24.     x2 = floor(x2 * c + y2 * s);  
  25.     y2 = floor(-x2 * s + y2 * c);  
  26.     cleardevice();  
  27.     line(x1, y1 ,x2, y2);  
  28.     getch();  
  29.     closegraph();  
  30. return 0;  
  31. }  

Output:

Before rotation

Rotation
Rotation
Rotation

After rotation

Rotation

Program to rotate a Triangle:

  1. #include<stdio.h>  
  2. #include<graphics.h>  
  3. #include<math.h>  
  4. main()  
  5. {  
  6.     intgd=0,gm,x1,y1,x2,y2,x3,y3;  
  7.     double s,c, angle;  
  8.     initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");  
  9.     setcolor(RED);  
  10.     printf("Enter coordinates of triangle: ");  
  11.     scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2, &x3, &y3);  
  12.     setbkcolor(WHITE);  
  13.     cleardevice();  
  14.     line(x1,y1,x2,y2);  
  15.     line(x2,y2, x3,y3);  
  16.     line(x3, y3, x1, y1);  
  17.     getch();  
  18.     setbkcolor(BLACK);  
  19.     printf("Enter rotation angle: ");  
  20.     scanf("%lf", &angle);  
  21.     setbkcolor(WHITE);  
  22.     c = cos(angle *M_PI/180);  
  23.     s = sin(angle *M_PI/180);  
  24.     x1 = floor(x1 * c + y1 * s);  
  25.     y1 = floor(-x1 * s + y1 * c);  
  26.     x2 = floor(x2 * c + y2 * s);  
  27.     y2 = floor(-x2 * s + y2 * c);  
  28.     x3 = floor(x3 * c + y3 * s);  
  29.     y3 = floor(-x3 * s + y3 * c);  
  30.     cleardevice();  
  31.     line(x1, y1 ,x2, y2);  
  32.     line(x2,y2, x3,y3);  
  33.     line(x3, y3, x1, y1);  
  34.     getch();  
  35.     closegraph();  
  36.     return 0;  
  37. }  

Output:

Before rotation

Rotation
Rotation
Rotation

After rotation

Rotation

Comment / Reply From