Rotate 3D Point Around Z-Axis
Rotate 3D Point Around Z-Axis
Rotate a 3D point (or points) around the Z-axis by angle θ (radians). For each point p=(x,y,z), compute p′=Rz(θ)p
Z-Axis Rotation Matrix:
Rz(θ)=cosθsinθ0−sinθcosθ0001Transformation:
x′=xcosθ−ysinθy′=xsinθ+ycosθz′=zExamples
Input: points = [1, 0, 0], theta = π/2
Output: [0, 1, 0]
Input: points = [[1, 0, 0], [0, 1, 2]], theta = π/2
Output: [[0, 1, 0], [-1, 0, 2]] (approx)
Hint 1
Handle single point by reshaping to (1,3), process, then reshape back to (3,)
Hint 2
Extract x, y, z columns and apply rotation formulas vectorized across all points.
Requirements
- Accept single point: shape (3,)(3,)
- Accept batch of points: (N,3)(N,3)
- Return same shape as input (always
np.ndarray) - θθ is any real number (can be negative)
- Must be vectorized over N
Constraints
- N≤10⁵
- NumPy only; time limit: 300ms
Log in to take notes on this problem
Accepts: array
Accepts: number
Rotate 3D Point Around Z-Axis
Rotate 3D Point Around Z-Axis
Rotate a 3D point (or points) around the Z-axis by angle θ (radians). For each point p=(x,y,z), compute p′=Rz(θ)p
Z-Axis Rotation Matrix:
Rz(θ)=cosθsinθ0−sinθcosθ0001Transformation:
x′=xcosθ−ysinθy′=xsinθ+ycosθz′=zExamples
Input: points = [1, 0, 0], theta = π/2
Output: [0, 1, 0]
Input: points = [[1, 0, 0], [0, 1, 2]], theta = π/2
Output: [[0, 1, 0], [-1, 0, 2]] (approx)
Hint 1
Handle single point by reshaping to (1,3), process, then reshape back to (3,)
Hint 2
Extract x, y, z columns and apply rotation formulas vectorized across all points.
Requirements
- Accept single point: shape (3,)(3,)
- Accept batch of points: (N,3)(N,3)
- Return same shape as input (always
np.ndarray) - θθ is any real number (can be negative)
- Must be vectorized over N
Constraints
- N≤10⁵
- NumPy only; time limit: 300ms
Log in to take notes on this problem
Accepts: array
Accepts: number