Apply 4×4 Homogeneous Transform
Apply 4×4 Homogeneous Transform
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=[R0t1]where R∈R3×3(rotation), t∈R3 (translation)
Transformation Process:
-
Convert point to homogeneous: ph=(x,y,z,1)
-
Apply transform: ph′=Tph
-
Extract spatial part: p′=(x′,y′,z′)
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
Log in to take notes on this problem
Accepts: array
Accepts: array
Apply 4×4 Homogeneous Transform
Apply 4×4 Homogeneous Transform
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=[R0t1]where R∈R3×3(rotation), t∈R3 (translation)
Transformation Process:
-
Convert point to homogeneous: ph=(x,y,z,1)
-
Apply transform: ph′=Tph
-
Extract spatial part: p′=(x′,y′,z′)
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
Log in to take notes on this problem
Accepts: array
Accepts: array