Roll, Pitch, Yaw to a Rotation Matrix
Implement rpy_to_matrix(roll, pitch, yaw) returning the 3x3 matrix RzRyRx. Angles are in radians.
Examples
All three angles zero: the identity
- Input
- rpy_to_matrix(0, 0, 0)
- Output
- [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
Yaw alone, 90 degrees: x turns onto y
- Input
- rpy_to_matrix(0, 0, 1.5707963267948966)
- Output
- [[0, -1, 0], [1, 0, 0], [0, 0, 1]]
Roll alone, 90 degrees: y tips onto z
- Input
- rpy_to_matrix(1.5707963267948966, 0, 0)
- Output
- [[1, 0, 0], [0, 0, -1], [0, 1, 0]]
Hints
Hint 1
Use a matrix product rather than nested loops, and check which operand transposes.
Hint 2
A common slip here: multiplied the three rotations in xyz order instead of zyx.
Requirements
roll: rotation about x, radianspitch: rotation about y, radiansyaw: rotation about z, radiansReturn (3, 3) rotation matrix R_z(yaw) @ R_y(pitch) @ R_x(roll)
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Try similar problems(4)
Industrial Robotics: Kinematics and Control · ~12 min
Industrial Robotics: Kinematics and Control · ~10 min
Industrial Robotics: Kinematics and Control · ~14 min
Industrial Robotics: Kinematics and Control · ~12 min
Where this shows up
6 employers weight this skill
4 autonomy companies, 2 defense companies. Top match scores 93.
import numpy as np
def rpy_to_matrix(roll, pitch, yaw):
"""
ZYX roll-pitch-yaw angles to a rotation matrix.
Args:
roll: rotation about x, radians
pitch: rotation about y, radians
yaw: rotation about z, radians
Returns:
(3, 3) rotation matrix R_z(yaw) @ R_y(pitch) @ R_x(roll)
"""
# YOUR CODE HERE
pass