Denavit-Hartenberg Link Transform

~16 mincode completion

Implement dh_transform(theta, d, a, alpha) returning the 4x4 matrix.

Examples

All four parameters zero is the identity

Input
dh_transform(0, 0, 0, 0)
Output
[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]

theta = pi/2 with a unit link: rotate, then the link points along the new x

Input
dh_transform(1.5707963267948966, 0, 1, 0)
Output
[[0, -1, 0, 0], [1, 0, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]

d alone is a translation along z

Input
dh_transform(0, 2, 0, 0)
Output
[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 2], [0, 0, 0, 1]]

Hints

Hint 1

Convert the input with before doing elementwise work.

Hint 2

Watch for this: applied alpha before theta.

Requirements

  • theta: joint angle about z (radians)

  • d: offset along z

  • a: link length along x

  • alpha: twist about x (radians)

  • Return (4, 4) homogeneous transform

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~16 min

6 employers weight this skill

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

Python
import numpy as np


def dh_transform(theta, d, a, alpha):
    """
    Standard Denavit-Hartenberg link transform.

    Args:
        theta: joint angle about z (radians)
        d:     offset along z
        a:     link length along x
        alpha: twist about x (radians)

    Returns:
        (4, 4) homogeneous 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.