v9.1.1
Menu

2D Rotation Matrix

easyFREEGeometric TransformationsComputer Vision 2

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
  • Inputs: theta_deg is the angle in degrees (90∘90^\circ), and points holds two 2D points, [1,0][1, 0] and [0,1][0, 1].
  • 90∘90^\circ is π2\frac{\pi}{2} radians, so cos⁡θ=0\cos\theta = 0 and sin⁡θ=1\sin\theta = 1. The rotation matrix becomes [0−110]\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}.
  • Point [1,0][1, 0]: x′=1⋅0−0⋅1=0x' = 1 \cdot 0 - 0 \cdot 1 = 0 and y′=1⋅1+0⋅0=1y' = 1 \cdot 1 + 0 \cdot 0 = 1, giving [0.0,1.0][0.0, 1.0]. The xx-axis unit vector lands on the yy-axis.
  • Point [0,1][0, 1]: x′=0⋅0−1⋅1=−1x' = 0 \cdot 0 - 1 \cdot 1 = -1 and y′=0⋅1+1⋅0=0y' = 0 \cdot 1 + 1 \cdot 0 = 0, giving [−1.0,0.0][-1.0, 0.0].
  • Output: a list with one rotated [x′,y′][x', y'] pair per input point in input order, each coordinate rounded to 4 decimal places: [[0.0, 1.0], [-1.0, 0.0]].
  • Notice that a positive angle turns points counter-clockwise. In floating point, cos⁡90∘\cos 90^\circ comes out near 6×10−176 \times 10^{-17}, not exactly 0, and rounding to 4 decimals turns it into a clean 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

Learn this in

More from Computer Vision 2

solution.py

Test results

Sign in to run your code against the test cases.