Quaternion.h
Quaternion static Slerp(Quaternion a, Quaternion b, double t)
	{
		Quaternion result = Quaternion();

		//calculate angle between them
		float cosHalfTheta = Dot(a, b);

		//if a==b or a==-b then theta = 0 and we can return a
		if (abs(cosHalfTheta) >= 1.0)
		{
			result = a;
			return result;
		}

		//calculate temporary values
		float halfTheta = acos(cosHalfTheta);
		float sinHalfTheta = (float)sqrt(1.0f - cosHalfTheta * cosHalfTheta);

		//if theta = 180 degrees then result is not fully defined
		//we could rotate around any axis normal to a or b

		if (fabs(sinHalfTheta) < 0.001)
		{
			result.r = (a.r * 0.5f + b.r * 0.5f);
			result.i = (a.i * 0.5f + b.i * 0.5f);
			result.j = (a.j * 0.5f + b.j * 0.5f);
			result.k = (a.k * 0.5f + b.k * 0.5f);
			return result;
		}

		float ratioA = (float)sin((1 - t) * halfTheta) / sinHalfTheta;
		float ratioB = (float)sin(t * halfTheta) / sinHalfTheta;

		//calculate Quaternion
		result.r = (a.r * ratioA + b.r * ratioB);
		result.i = (a.i * ratioA + b.i * ratioB);
		result.j = (a.j * ratioA + b.j * ratioB);
		result.k = (a.k * ratioA + b.k * ratioB);
		return result;
	}
//Spherically interpolates between a and b
Spherically interpolates between a and b
Spherically interpolates between a and b
Quaternion static Slerp(Quaternion a, Quaternion b, double t)
	{
		Quaternion result = Quaternion();
		float cosHalfTheta = Dot(a, b);
		if (abs(cosHalfTheta) >= 1.0)
		{
			result = a;
			return result;
		}
		float halfTheta = acos(cosHalfTheta);
		float sinHalfTheta = (float)sqrt(1.0f - cosHalfTheta * cosHalfTheta);
		if (fabs(sinHalfTheta) < 0.001)
		{
			result.r = (a.r * 0.5f + b.r * 0.5f);
			result.i = (a.i * 0.5f + b.i * 0.5f);
			result.j = (a.j * 0.5f + b.j * 0.5f);
			result.k = (a.k * 0.5f + b.k * 0.5f);
			return result;
		}
		float ratioA = (float)sin((1 - t) * halfTheta) / sinHalfTheta;
		float ratioB = (float)sin(t * halfTheta) / sinHalfTheta;
		result.r = (a.r * ratioA + b.r * ratioB);
		result.i = (a.i * ratioA + b.i * ratioB);
		result.j = (a.j * ratioA + b.j * ratioB);
		result.k = (a.k * ratioA + b.k * ratioB);
		return result;
	}
Quaternion static Slerp ( Quaternion a , Quaternion b , double t ) { Quaternion result = Quaternion ( ) ; float cosHalfTheta = Dot ( a , b ) ; if ( abs ( cosHalfTheta ) >= 1.0 ) { result = a ; return result ; } float halfTheta = acos ( cosHalfTheta ) ; float sinHalfTheta = ( float ) sqrt ( 1.0f - cosHalfTheta * cosHalfTheta ) ; if ( fabs ( sinHalfTheta ) < 0.001 ) { result . r = ( a . r * 0.5f + b . r * 0.5f ) ; result . i = ( a . i * 0.5f + b . i * 0.5f ) ; result . j = ( a . j * 0.5f + b . j * 0.5f ) ; result . k = ( a . k * 0.5f + b . k * 0.5f ) ; return result ; } float ratioA = ( float ) sin ( ( 1 - t ) * halfTheta ) / sinHalfTheta ; float ratioB = ( float ) sin ( t * halfTheta ) / sinHalfTheta ; result . r = ( a . r * ratioA + b . r * ratioB ) ; result . i = ( a . i * ratioA + b . i * ratioB ) ; result . j = ( a . j * ratioA + b . j * ratioB ) ; result . k = ( a . k * ratioA + b . k * ratioB ) ; return result ; }
Spherically interpolates between a and b
Spherically interpolates between a and b
//calculate angle between them //if a==b or a==-b then theta = 0 and we can return a //calculate temporary values //if theta = 180 degrees then result is not fully defined //we could rotate around any axis normal to a or b //calculate Quaternion