Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-225

Quaternion SLERP

Problem

Spherical linear interpolation between unit quaternions q1 and q2 at parameter t:

If dot(q1, q2) < 0, negate q2 for the shortest path. If the adjusted dot exceeds 0.9995, normalize the linear interpolation; otherwise use theta = acos(dot) and interpolate with sin weights. Return a unit quaternion.

Hint

Negating a quaternion represents the same rotation, so pick the hemisphere closer to q1.

Test cases

case 1
in: [[1,0,0,0],[0,0,0,1],0.5]
expected: [0.7071067811865475,0,0,0.7071067811865475]
case 2
in: [[1,0,0,0],[0,0,0,1],0]
expected: [1,0,0,0]
case 3
in: [[1,0,0,0],[0,0,0,1],1]
expected: [0,0,0,1]
case 4
in: [[0.7071067811865476,0,0,0.7071067811865476],[-0.7071067811865476,0,0,-0.7071067811865476],0.5]
expected: [0.7071067811865476,0,0,0.7071067811865476]
Starter codePython
def quaternion_slerp(q1, q2, t):
    # Your code here
    pass

4 test cases · run your code against them in the editor