Computer Graphics 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
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-
P1 = P0 x cosθ – Q0 x sinθ
Q1 = P0 x sinθ + Q0 x cosθ
We can represent the coordinates of point A (P0, Q0) by using standard trigonometry-
P0 = r cosθ………… (1)
Q0 = r sinθ………… (2)
We can also define point A (P1, Q1) in the same way-
P1 = r cos (θ+β) = r cosθcosβ – r sinθsinβ …………. (3)
Q1 = r sin (θ+β) = r cosθsinβ + r sinθcosβ …………. (4)
By using equation (1) (2) (3) (4), we will get-
P1= P0 cosθ – P0 sinθ
Q1= P0 sinθ + P0 cosθ
We can also represent the Rotation in the form of matrix–
Homogeneous Coordinates Representation: The Rotation can also be represented in the form of 3 x 3 Rotation matrix-
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.
(P0, Q0) = (0, 0)
Rotation Angle (θ) = 30°
Let the new coordinates of line = (P1, Q1)
We can apply the rotation matrix, then,
P1= P0 x cosθ – Q0 x sinθ
= 5 x cos30 – 5 x sin30
= 5 x( √3/2) – 5 x (1/2)
= 4.33 – 2.5
Q1= P0 x sinθ + Q0 x cosθ
= 5 x sin30 + 5 x cos30
= 5 x (1/2) + 5 x( √3/2)
= 2.5 + 4.33 = 6.83
Thus, the new endpoint coordinates of the line are = (P1, Q1) = (1.83, 6.83)