![]() |
VOOZH | about |
We have to rotate an object by a given angle about a given pivot point and print the new co-ordinates.
Examples:
Input : {(100, 100), (150, 200), (200, 200),
(200, 150)} is to be rotated about
(0, 0) by 90 degrees
Output : (-100, 100), (-200, 150), (-200, 200), (-150, 200)
Input : {(100, 100), (100, 200), (200, 200)}
is to be rotated about (50, -50) by
-45 degrees
Output : (191.421, 20.7107), (262.132, 91.4214),
(332.843, 20.7107)
In order to rotate an object we need to rotate each vertex of the figure individually.
On rotating a point P(x, y) by an angle A about the origin we get a point P'(x', y'). The values of x' and y' can be calculated as follows:-
We know that,
x = rcosB, y = rsinB
x' = rcos(A+B) = r(cosAcosB - sinAsinB) = cosA - sinA = xcosA - ysinA
y' = rsin(A+B) = r(sinAcosB + cosAsinB) = sinA + cosA = xsinA + ycosA
Rotational Matrix Equation:-
Output:
(-100, 100), (-200, 150), (-200, 200), (-150, 200)
Time Complexity: O(N)
Auxiliary Space: O(1)
References: Rotation matrix