TensorTonicTensorTonic
Problems
Study PlansProjectsInterviewPricingFeedback
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)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} Rz​(θ)=​cosθsinθ0​−sinθcosθ0​001​​

Transformation:

x′=xcos⁡θ−ysin⁡θy′=xsin⁡θ+ycos⁡θz′=zx' = x \cos\theta - y \sin\theta \\ y' = x \sin\theta + y \cos\theta \\z' = z x′=xcosθ−ysinθy′=xsinθ+ycosθ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
Homogeneous TransformAngle Between 3dNormalize 3dImage Rotation NearestVector Norm 3d

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

You must run your code first.
PrevNext

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)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} Rz​(θ)=​cosθsinθ0​−sinθcosθ0​001​​

Transformation:

x′=xcos⁡θ−ysin⁡θy′=xsin⁡θ+ycos⁡θz′=zx' = x \cos\theta - y \sin\theta \\ y' = x \sin\theta + y \cos\theta \\z' = z x′=xcosθ−ysinθy′=xsinθ+ycosθ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
Homogeneous TransformAngle Between 3dNormalize 3dImage Rotation NearestVector Norm 3d

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

You must run your code first.