PIXELBANKv8.2.1
Menu

2D Rotation Matrix

Implement a 2D rotation transformation using a rotation matrix to rotate a list of 2D points by a given angle θ\theta 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 RR for a 2D rotation is given by:

[cosθsinθsinθcosθ]\begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix}

To apply this transformation to a point [x,y][x, y], we can use the following steps:

  1. Convert the angle from degrees to radians.
  2. Compute the cosine and sine of the angle.
  3. Apply the rotation matrix to the point using the formulas: x=xcosθysinθx' = x\cos\theta - y\sin\theta and y=xsinθ+ycosθy' = x\sin\theta + y\cos\theta. The key formulas are:
x=xcosθysinθx' = x\cos\theta - y\sin\theta y=xsinθ+ycosθy' = x\sin\theta + y\cos\theta

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 θ\theta is given as 90 degrees, which in radians is π2\frac{\pi}{2}, so we calculate cosθ=cos(π2)=0\cos\theta = \cos(\frac{\pi}{2}) = 0 and sinθ=sin(π2)=1\sin\theta = \sin(\frac{\pi}{2}) = 1.
  • For the point [1,0][1, 0], we apply the rotation transformation: x=1cos(π2)0sin(π2)=0x' = 1\cos(\frac{\pi}{2}) - 0\sin(\frac{\pi}{2}) = 0 and y=1sin(π2)+0cos(π2)=1y' = 1\sin(\frac{\pi}{2}) + 0\cos(\frac{\pi}{2}) = 1, resulting in [0.0,1.0][0.0, 1.0].
  • For the point [0,1][0, 1], we apply the rotation transformation: x=0cos(π2)1sin(π2)=1x' = 0\cos(\frac{\pi}{2}) - 1\sin(\frac{\pi}{2}) = -1 and y=0sin(π2)+1cos(π2)=0y' = 0\sin(\frac{\pi}{2}) + 1\cos(\frac{\pi}{2}) = 0, resulting in [1.0,0.0][-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]][[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

Test Results

0/0
Run code to see test results.