Rotation from Axis and Angle

~16 mincode completion

Implement axis_angle_to_matrix(axis, angle).

Examples

z-axis, 90 degrees

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

x-axis, 180 degrees flips y and z

Input
axis_angle_to_matrix([1, 0, 0], 3.141592653589793)
Output
[[1, 0, 0], [0, -1, 0], [0, 0, -1]]

Angle 0 is the identity for any axis

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

Hints

Hint 1

gives the magnitude in one call; pick the axis deliberately.

Hint 2

Do not forget to normalise the axis. That step is easy to skip.

Requirements

  • : (3,) rotation axis, not necessarily unit length

  • angle: rotation in radians, counterclockwise about the axis

  • Return (3, 3) rotation matrix

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 axis_angle_to_matrix(axis, angle):
    """
    Rodrigues rotation formula.

    Args:
        axis:  (3,) rotation axis, not necessarily unit length
        angle: rotation in radians, counterclockwise about the axis

    Returns:
        (3, 3) rotation matrix
    """
    # 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.