All problems
Quaternion to Rotation Matrix
Problem
Convert the quaternion q = [w, x, y, z] into a 3x3 rotation matrix.
Normalize q first, then use
R = [[1-2(y^2+z^2), 2(xy-wz), 2(xz+wy)], [2(xy+wz), 1-2(x^2+z^2), 2(yz-wx)], [2(xz-wy), 2(yz+wx), 1-2(x^2+y^2)]]
Hint
The quaternion (cos(theta/2), axis*sin(theta/2)) rotates by theta about the normalized axis.
Test cases
case 1
in: [[1,0,0,0]]
expected: [[1,0,0],[0,1,0],[0,0,1]]
case 2
in: [[0,0,0,1]]
expected: [[-1,0,0],[0,-1,0],[0,0,1]]
case 3
in: [[0.7071067811865476,0,0,0.7071067811865476]]
expected: [[0,-1,0],[1,0,0],[0,0,1]]
case 4
in: [[0,1,0,0]]
expected: [[1,0,0],[0,-1,0],[0,0,-1]]
Starter codePython
def quaternion_to_rotation(q):
# Your code here
pass4 test cases · run your code against them in the editor