TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Apply 4×4 Homogeneous Transform

3D Geometry
Medium

A homogeneous transformation combines a three-dimensional linear transformation and a translation in one 4×44 \times 44×4 matrix:

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

Here, RRR is a 3×33 \times 33×3 matrix and ttt is a three-dimensional translation vector. For a point p=(x,y,z)p = (x, y, z)p=(x,y,z), form its homogeneous coordinate:

ph=[xyz1]Tp_h = \begin{bmatrix} x & y & z & 1 \end{bmatrix}^{\mathsf T}ph​=[x​y​z​1​]T

Apply the transformation:

ph′=Tphp'_h = T p_hph′​=Tph​

Return the first three coordinates of every transformed point. A single input point must produce an array of shape (3,)(3,)(3,), while a batch must produce an array of shape (N,3)(N, 3)(N,3).

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.0, 2.0, 3.0]

Explanation: Appending 1 allows the last column of T to translate the point by (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.0, 1.0, 0.0], [0.0, 0.0, 0.0]]

Hint 1

np.ones((points.shape[0], 1)) creates the homogeneous coordinate for a batch.

Hint 2

(T @ points_h.T).T applies one transform to every point at once.

Requirements

  • Accept T as a list representing a 4×44 \times 44×4 homogeneous transformation
  • Accept either one three-dimensional point or a batch of points
  • Return a NumPy array with shape (3,)(3,)(3,) for one point or (N,3)(N, 3)(N,3) for a batch
  • Process a batch without a Python loop over its points

Constraints

  • T has shape (4,4)(4, 4)(4,4)
  • Points has shape (3,)(3,)(3,) or (N,3)(N, 3)(N,3)
  • 1≤N≤100,0001 \leq N \leq 100{,}0001≤N≤100,000
  • Use NumPy only
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

A homogeneous transformation combines a three-dimensional linear transformation and a translation in one 4×44 \times 44×4 matrix:

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

Here, RRR is a 3×33 \times 33×3 matrix and ttt is a three-dimensional translation vector. For a point p=(x,y,z)p = (x, y, z)p=(x,y,z), form its homogeneous coordinate:

ph=[xyz1]Tp_h = \begin{bmatrix} x & y & z & 1 \end{bmatrix}^{\mathsf T}ph​=[x​y​z​1​]T

Apply the transformation:

ph′=Tphp'_h = T p_hph′​=Tph​

Return the first three coordinates of every transformed point. A single input point must produce an array of shape (3,)(3,)(3,), while a batch must produce an array of shape (N,3)(N, 3)(N,3).

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.0, 2.0, 3.0]

Explanation: Appending 1 allows the last column of T to translate the point by (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.0, 1.0, 0.0], [0.0, 0.0, 0.0]]

Hint 1

np.ones((points.shape[0], 1)) creates the homogeneous coordinate for a batch.

Hint 2

(T @ points_h.T).T applies one transform to every point at once.

Requirements

  • Accept T as a list representing a 4×44 \times 44×4 homogeneous transformation
  • Accept either one three-dimensional point or a batch of points
  • Return a NumPy array with shape (3,)(3,)(3,) for one point or (N,3)(N, 3)(N,3) for a batch
  • Process a batch without a Python loop over its points

Constraints

  • T has shape (4,4)(4, 4)(4,4)
  • Points has shape (3,)(3,)(3,) or (N,3)(N, 3)(N,3)
  • 1≤N≤100,0001 \leq N \leq 100{,}0001≤N≤100,000
  • Use NumPy only
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.