v9.1.1
Menu

Compose 3D Transformations

mediumFREE2D/3D TransformationsTransformationsCV: Image Formation

Compose multiple 3D transformation matrices in the correct order using NumPy.

3D transformations are represented as 4×4 homogeneous matrices. Composing transformations requires multiplying matrices in reverse order of application.

If we want to apply T1 first, then T2: Result = T2 @ T1

Return the composed matrix as a nested list of integers (e.g. 10, not 10.0); all test matrices have integer entries.

Common 3D transformations:

  • Translation: Move by (tx, ty, tz)
  • Rotation: Rotate around X, Y, or Z axis
  • Scale: Scale by (sx, sy, sz)

This is crucial for camera positioning, object manipulation, and scene graph traversal in 3D CV.

Example

Input
transforms = [
  [[1,0,0,5],[0,1,0,0],[0,0,1,0],[0,0,0,1]],  # Translate X by 5
  [[2,0,0,0],[0,2,0,0],[0,0,2,0],[0,0,0,1]]   # Scale by 2
]
Output
[[2,0,0,10],[0,2,0,0],[0,0,2,0],[0,0,0,1]]
Reasoning
  • transforms is a list of 4×44 \times 4 homogeneous matrices in the order they act on a point: here T1T_1 translates by (5,0,0)(5, 0, 0) and T2T_2 scales every axis by 2.
  • A point p=[x,y,z,1]Tp = [x, y, z, 1]^T ends up at T2(T1p)T_2 (T_1 p), so the one matrix doing both is M=T2T1M = T_2 T_1: the transform applied later sits on the left.
  • Multiplying out, the upper-left 3×33 \times 3 block is 2I⋅I=2I2I \cdot I = 2I, and the translation column becomes 2⋅(5,0,0)=(10,0,0)2 \cdot (5, 0, 0) = (10, 0, 0), giving [[2,0,0,10],[0,2,0,0],[0,0,2,0],[0,0,0,1]].
  • Check with the origin: (0,0,0)→(5,0,0)(0,0,0) \to (5,0,0) after translating, then →(10,0,0)\to (10,0,0) after scaling, which is exactly the last column of MM.
  • Notice the translation got scaled too. Swapping the two matrices gives T1T2T_1 T_2, whose translation column stays (5,0,0)(5, 0, 0): composition is not commutative.
  • The bottom row stays (0,0,0,1)(0, 0, 0, 1), and every entry is a whole number, returned as an integer.

Constraints

  • transforms: List of 4×4 transformation matrices
  • Return: Single composed 4×4 matrix
  • Apply transforms in order (first in list applied first)

Learn this in

More from CV: Image Formation

solution.py

Test results

Sign in to run your code against the test cases.