Invert a Homogeneous Transform

~10 mincode completion

Implement invert_transform(T).

Examples

A pure translation inverts to the opposite translation

Input
invert_transform([[1, 0, 0, 1], [0, 1, 0, 2], [0, 0, 1, 3], [0, 0, 0, 1]])
Output
[[1, 0, 0, -1], [0, 1, 0, -2], [0, 0, 1, -3], [0, 0, 0, 1]]

A pure rotation inverts to its transpose

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

Rotation plus translation: the translation is rotated back, not just negated

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

Hints

Hint 1

Use a matrix product rather than nested loops, and check which operand transposes.

Hint 2

Watch for this: negated the translation without rotating it.

Requirements

  • : (4, 4) array with an orthogonal 3x3 rotation block

  • Return (4, 4) inverse transform

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~10 min

6 employers weight this skill

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

Python
import numpy as np


def invert_transform(T):
    """
    Closed-form inverse of a 4x4 homogeneous transform.

    Args:
        T: (4, 4) array with an orthogonal 3x3 rotation block

    Returns:
        (4, 4) inverse transform
    """
    # 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.