Build a Homogeneous Transform

~8 mincode completion

Implement homogeneous_transform(R, t) returning the 4x4 matrix.

Examples

Identity rotation with a translation of [1, 2, 3]

Input
homogeneous_transform([[1, 0, 0], [0, 1, 0], [0, 0, 1]], [1, 2, 3])
Output
[[1, 0, 0, 1], [0, 1, 0, 2], [0, 0, 1, 3], [0, 0, 0, 1]]

A 90-degree turn about z with no translation

Input
homogeneous_transform([[0, -1, 0], [1, 0, 0], [0, 0, 1]], [0, 0, 0])
Output
[[0, -1, 0, 0], [1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]

Hints

Hint 1

Convert the input with before doing elementwise work.

Hint 2

A common slip here: put the translation in the last row instead of the last column.

Requirements

  • R: (3, 3) rotation matrix

  • : (3,) translation

  • Return (4, 4) array [[R, t], [0, 0, 0, 1]]

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~8 min

6 employers weight this skill

4 autonomy companies, 2 defense companies. Top match scores 93.

Python
import numpy as np


def homogeneous_transform(R, t):
    """
    4x4 homogeneous transform from a rotation and a translation.

    Args:
        R: (3, 3) rotation matrix
        t: (3,) translation

    Returns:
        (4, 4) array [[R, t], [0, 0, 0, 1]]
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.