TensorTonicTensorTonic
Problems
Study PlansProjectsInterviewPricingFeedback
Problems
Loading...
1 / 1

Apply 4×4 Homogeneous Transform

3D Geometry
Medium

In robotics / graphics / 3D vision, a 4×4 homogeneous transform encodes rotation + translation. Given a transform matrix T and 3D point(s), convert each point to homogeneous coordinates, apply the transform, and return the spatial coordinates.

Homogeneous Transform:

T=[Rt01]T = \begin{bmatrix} R & t \\ 0 & 1 \end{bmatrix} T=[R0​t1​]

where R∈R3×3R \in \mathbb{R}^{3 \times 3}R∈R3×3(rotation), t∈R3t \in \mathbb{R}^3t∈R3 (translation)

Transformation Process:

  1. Convert point to homogeneous: ph=(x,y,z,1)p_h =(x,y,z,1)ph​=(x,y,z,1)

  2. Apply transform: ph′=Tphp^′_h=Tp_hph′​=Tph​

  3. Extract spatial part: p′=(x′,y′,z′)p^′=(x^′,y^′,z^′)p′=(x′,y′,z′)

Loading visualization...

Examples

Input: T = [[1,0,0,1],[0,1,0,2],[0,0,1,3],[0,0,0,1]], points = [0,0,0]

Output: [1, 2, 3]

Input: T = [[0,-1,0,1],[1,0,0,0],[0,0,1,0],[0,0,0,1]], points = [[1,0,0],[0,1,0]]

Output: [[1,1,0], [0,0,0]]

Hint 1

Handle single point by reshaping to (1,3), process, then reshape back to (3,).

Hint 2

Use np.hstack() to append 1s, then (T @ points_h.T).T for matrix multiplication.

Requirements

  • T: NumPy array of shape (4,4)
  • Points: single point (3,) or batch (N,3)
  • Return: if single → (3,) array, if batch → (N,3) array
  • Convert to homogeneous coords by appending 1
  • Use matrix multiplication with T
  • Drop last coordinate from result
  • Fully vectorized over batch

Constraints

  • Batch size N≤10⁵
  • NumPy only; time limit: 400ms
Try Similar Problems
Rotate Around ZNormalize 3dAngle Between 3dVector Norm 3dMatrix Inverse

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.
PrevNext

Apply 4×4 Homogeneous Transform

3D Geometry
Medium

In robotics / graphics / 3D vision, a 4×4 homogeneous transform encodes rotation + translation. Given a transform matrix T and 3D point(s), convert each point to homogeneous coordinates, apply the transform, and return the spatial coordinates.

Homogeneous Transform:

T=[Rt01]T = \begin{bmatrix} R & t \\ 0 & 1 \end{bmatrix} T=[R0​t1​]

where R∈R3×3R \in \mathbb{R}^{3 \times 3}R∈R3×3(rotation), t∈R3t \in \mathbb{R}^3t∈R3 (translation)

Transformation Process:

  1. Convert point to homogeneous: ph=(x,y,z,1)p_h =(x,y,z,1)ph​=(x,y,z,1)

  2. Apply transform: ph′=Tphp^′_h=Tp_hph′​=Tph​

  3. Extract spatial part: p′=(x′,y′,z′)p^′=(x^′,y^′,z^′)p′=(x′,y′,z′)

Loading visualization...

Examples

Input: T = [[1,0,0,1],[0,1,0,2],[0,0,1,3],[0,0,0,1]], points = [0,0,0]

Output: [1, 2, 3]

Input: T = [[0,-1,0,1],[1,0,0,0],[0,0,1,0],[0,0,0,1]], points = [[1,0,0],[0,1,0]]

Output: [[1,1,0], [0,0,0]]

Hint 1

Handle single point by reshaping to (1,3), process, then reshape back to (3,).

Hint 2

Use np.hstack() to append 1s, then (T @ points_h.T).T for matrix multiplication.

Requirements

  • T: NumPy array of shape (4,4)
  • Points: single point (3,) or batch (N,3)
  • Return: if single → (3,) array, if batch → (N,3) array
  • Convert to homogeneous coords by appending 1
  • Use matrix multiplication with T
  • Drop last coordinate from result
  • Fully vectorized over batch

Constraints

  • Batch size N≤10⁵
  • NumPy only; time limit: 400ms
Try Similar Problems
Rotate Around ZNormalize 3dAngle Between 3dVector Norm 3dMatrix Inverse

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.