Rotate 2D Points
~12 mincode completion
Implement rotate_points(points, theta).
pointshas shape(N, 2).thetais in radians, counterclockwise.- Return an array of shape
(N, 2).
Examples
theta = 0 leaves the points unchanged
- Input
- rotate_points([[1, 0], [0, 1]], 0)
- Output
- [[1, 0], [0, 1]]
90 degrees counterclockwise: (1,0) -> (0,1), (0,1) -> (-1,0)
- Input
- rotate_points([[1, 0], [0, 1], [1, 1]], 1.5707963267948966)
- Output
- [[0, 1], [-1, 0], [-1, 1]]
45 degrees sends (1,0) onto the diagonal
- Input
- rotate_points([[1, 0]], 0.7853981633974483)
- Output
- [[0.70711, 0.70711]]
Hints
Hint 1
Use a matrix product rather than nested loops, and check which operand transposes.
Hint 2
Reach for counterclockwise rather than clockwise.
Requirements
points: (N, 2) array of (x, y) rowstheta: rotation angle in radiansReturn (N, 2) array of rotated points
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~12 min
••••••••••••••••
8 employers weight this skill
4 autonomy companies, 1 defense company, 1 health and bio company, 1 enterprise vendor, 1 AI product company. Top match scores 93.
Python
import numpy as np
def rotate_points(points, theta):
"""
Rotate 2D points counterclockwise by theta radians.
Args:
points: (N, 2) array of (x, y) rows
theta: rotation angle in radians
Returns:
(N, 2) array of rotated points
"""
# YOUR CODE HERE
pass