📘
2D Rotation Matrix
Implement a 2D rotation transformation using a rotation matrix to rotate a list of 2D points by a given angle θ in degrees. The goal is to apply this transformation to each point and return the list of rotated points.
In geometric transformations, rotation is a fundamental concept that involves changing the orientation of an object in a 2D or 3D space. The rotation matrix is a mathematical representation of this transformation, which can be used to rotate points, vectors, and other geometric entities. The rotation matrix R for a 2D rotation is given by:
[cosθsinθ−sinθcosθ]To apply this transformation to a point [x,y], we can use the following steps:
- Convert the angle from degrees to radians.
- Compute the cosine and sine of the angle.
- Apply the rotation matrix to the point using the formulas: x′=xcosθ−ysinθ and y′=xsinθ+ycosθ. The key formulas are:
This technique is widely used in computer vision and image processing applications.
Example:
Input:
theta = 90 points = [[1, 0], [0, 1]]
Output:
[[0.0, 1.0], [-1.0, 0.0]]
Reasoning:
- The rotation angle θ is given as 90 degrees, which in radians is 2π, so we calculate cosθ=cos(2π)=0 and sinθ=sin(2π)=1.
- For the point [1,0], we apply the rotation transformation: x′=1cos(2π)−0sin(2π)=0 and y′=1sin(2π)+0cos(2π)=1, resulting in [0.0,1.0].
- For the point [0,1], we apply the rotation transformation: x′=0cos(2π)−1sin(2π)=−1 and y′=0sin(2π)+1cos(2π)=0, resulting in [−1.0,0.0].
- The final output is the list of rotated points, each coordinate rounded to 4 decimal places: [[0.0,1.0],[−1.0,0.0]].
Constraints:
- theta is in degrees
- points is a list of [x, y] pairs
- Return list of [x', y'] pairs rounded to 4 decimal places
- Use math.cos, math.sin, math.radians
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.