Problems
Loading...
1 / 1

Rotate 3D Point Around Z-Axis

3D Geometry
Medium

Rotate a 3D point (or points) around the Z-axis by angle θθ (radians). For each point p=(x,y,z)p=(x,y,z), compute p′=Rz(θ)p

Z-Axis Rotation Matrix:

Rz(θ)=[cosθsinθ0sinθcosθ0001]R_{z}(\theta) = \begin{bmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{bmatrix}

Transformation:

x=xcosθysinθy=xsinθ+ycosθz=zx' = x \cos\theta - y \sin\theta \\ y' = x \sin\theta + y \cos\theta \\z' = z
Loading visualization...

Examples

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
Try Similar Problems