3{
4
5
6 v0.normalize();
7 v1.normalize();
8
9
10 double dot = v0.dot(v1);
11
12
13
14
15
16 if (dot < 0.0f)
17 {
18 v1 = quaternion_negation(v1);
19 dot = -dot;
20 }
21
22 Quaterniond vdiff = quaternion_minus(v1, v0);
23
24 const double DOT_THRESHOLD = 0.9995;
25 if (dot > DOT_THRESHOLD)
26 {
27
28
29
30 Quaterniond result = scalar_product(vdiff, t);
31 result.normalize();
32 return result;
33 }
34
35
36 double theta_0 = acos(dot);
37 double theta = theta_0 * t;
38 double sin_theta = sin(theta);
39 double sin_theta_0 = sin(theta_0);
40
41 double s0 =
42 cos(theta) - dot * sin_theta / sin_theta_0;
43 double s1 = sin_theta / sin_theta_0;
44
45 return quaternion_plus(scalar_product(v0, s0), scalar_product(v1, s1));
46}