2D Rotation
The Rotation of any object depends upon the two points.
Rotation Point: It is also called the Pivot point.
Rotation Angle: It is denoted by Theta ().
We can rotate an object in two ways-
Clockwise: An object rotates clockwise if the value of the Rotation angle is negative (-).
Anti-Clockwise: An object rotates anti-clockwise if the value of the Rotation angle is positive (+).
We can apply Rotation on following objects-
- Straight Lines
- Curved Lines
- Polygon
- Circle
For Example-
Rotation of a Point: If we want to Rotate a point A (P0, Q0) that has a Rotation angle with distance r from origin to A` (P1, Q1) that has a Rotation angle
. Then, we can rotate by following Rotation equation-
![2D Rotation](https://static.tutorialandexample.com/computer-graphics/2d-rotation3.png)
![2D Rotation](https://static.tutorialandexample.com/computer-graphics/2d-rotation4.png)
We can represent the coordinates of point A (P0, Q0) by using standard trigonometry-
![2D Rotation](https://static.tutorialandexample.com/computer-graphics/2d-rotation5.png)
We can also define point A` (P1, Q1) in the same way-
![2D Rotation](https://static.tutorialandexample.com/computer-graphics/2d-rotation6.png)
By using equation (1) (2) (3) (4), we will get-
![2D Rotation](https://static.tutorialandexample.com/computer-graphics/2d-rotation7.png)
We can also represent the Rotation in the form of matrix-
![2D Rotation](https://static.tutorialandexample.com/computer-graphics/2d-rotation8.png)
Homogeneous Coordinates Representation: The Rotation can also be represented in the form of 3 x 3 Rotation matrix-
![2D Rotation](https://static.tutorialandexample.com/computer-graphics/2d-rotation9.png)
Example- A line segment with the starting point (0, 0) and ending points (5, 5). Apply 30-degree rotation anticlockwise direction on the line. Find the new coordinates of the line?
Solution- We can rotate the straight line by its endpoints with the same angle.
![2D Rotation](https://static.tutorialandexample.com/computer-graphics/2d-rotation10.png)
We have,
(P0, Q0) = (0, 0)
Rotation Angle () = 30°
Let the new coordinates of line = (P1, Q1)
We can apply the rotation matrix, then,
![2D Rotation](https://static.tutorialandexample.com/computer-graphics/2d-rotation11.png)
Thus, the new endpoint coordinates of the line are = (P1, Q1) = (1.83, 6.83)