#NEWLINE# def quaternion_slerp( quat0 , quat1 , fraction , spin = 0 , shortestpath = True ) : #NEWLINE# #INDENT# 'Return spherical linear interpolation between two quaternions.\n\n    >>> q0 = random_quaternion()\n    >>> q1 = random_quaternion()\n    >>> q = quaternion_slerp(q0, q1, 0.0)\n    >>> numpy.allclose(q, q0)\n    True\n    >>> q = quaternion_slerp(q0, q1, 1.0, 1)\n    >>> numpy.allclose(q, q1)\n    True\n    >>> q = quaternion_slerp(q0, q1, 0.5)\n    >>> angle = math.acos(numpy.dot(q0, q))\n    >>> numpy.allclose(2.0, math.acos(numpy.dot(q0, q1)) / angle) or         numpy.allclose(2.0, math.acos(-numpy.dot(q0, q1)) / angle)\n    True\n\n    ' #NEWLINE# q0 = unit_vector ( quat0 [ : 4 ] ) #NEWLINE# q1 = unit_vector ( quat1 [ : 4 ] ) #NEWLINE# if ( fraction == 0.0 ) : #NEWLINE# #INDENT# return q0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( fraction == 1.0 ) : #NEWLINE# #INDENT# return q1 #NEWLINE# #UNINDENT# #UNINDENT# d = numpy . dot ( q0 , q1 ) #NEWLINE# if ( abs ( ( abs ( d ) - 1.0 ) ) < _EPS ) : #NEWLINE# #INDENT# return q0 #NEWLINE# #UNINDENT# if ( shortestpath and ( d < 0.0 ) ) : #NEWLINE# #INDENT# d = ( - d ) #NEWLINE# q1 *= ( - 1.0 ) #NEWLINE# #UNINDENT# angle = ( math . acos ( d ) + ( spin * math . pi ) ) #NEWLINE# if ( abs ( angle ) < _EPS ) : #NEWLINE# #INDENT# return q0 #NEWLINE# #UNINDENT# isin = ( 1.0 / math . sin ( angle ) ) #NEWLINE# q0 *= ( math . sin ( ( ( 1.0 - fraction ) * angle ) ) * isin ) #NEWLINE# q1 *= ( math . sin ( ( fraction * angle ) ) * isin ) #NEWLINE# q0 += q1 #NEWLINE# return q0