Camera Points into the Robot Base Frame

~10 mincode completion

Implement transform_points(T, points) returning an (N, 3) array.

Examples

The identity transform returns the points unchanged

Input
transform_points([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]], [[1, 2, 3], [4, 5, 6]])
Output
[[1, 2, 3], [4, 5, 6]]

A pure translation shifts every point

Input
transform_points([[1, 0, 0, 1], [0, 1, 0, 2], [0, 0, 1, 3], [0, 0, 0, 1]], [[0, 0, 0], [1, 1, 1]])
Output
[[1, 2, 3], [2, 3, 4]]

Rotate about z by 90 degrees, then translate by [1, 0, 0]

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

Hints

Hint 1

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

Hint 2

Watch for this: applied the translation before the rotation.

Requirements

  • : (4, 4) transform from the points' frame to the target frame

  • points: (N, 3) points

  • Return (N, 3) transformed points

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 transform_points(T, points):
    """
    Apply a homogeneous transform to a stack of 3D points.

    Args:
        T:      (4, 4) transform from the points' frame to the target frame
        points: (N, 3) points

    Returns:
        (N, 3) transformed points
    """
    # 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.