ARCore中四元数的插值算法实现

Posted bky2016

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ARCore中四元数的插值算法实现相关的知识,希望对你有一定的参考价值。

ARCore中四元数差值算法:

其中t的取值范围为[0, 1],当 t = 0 时,结果为a;当t = 1 时,结果为b。

 1   public static Quaternion makeInterpolated(Quaternion a, Quaternion b, float t) {
 2         Quaternion out = new Quaternion();
 3         float cosHalfTheta = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
 4         if(cosHalfTheta < 0.0F) {
 5             b = new Quaternion(b);
 6             cosHalfTheta = -cosHalfTheta;
 7             b.x = -b.x;
 8             b.y = -b.y;
 9             b.z = -b.z;
10             b.w = -b.w;
11         }
12 
13         float halfTheta = (float)Math.acos((double)cosHalfTheta);
14         float sinHalfTheta = (float)Math.sqrt((double)(1.0F - cosHalfTheta * cosHalfTheta));
15         float ratioA;
16         float ratioB;
17         if((double)Math.abs(sinHalfTheta) > 0.001D) {
18             float oneOverSinHalfTheta = 1.0F / sinHalfTheta;
19             ratioA = (float)Math.sin((double)((1.0F - t) * halfTheta)) * oneOverSinHalfTheta;
20             ratioB = (float)Math.sin((double)(t * halfTheta)) * oneOverSinHalfTheta;
21         } else {
22             ratioA = 1.0F - t;
23             ratioB = t;
24         }
25 
26         out.x = ratioA * a.x + ratioB * b.x;
27         out.y = ratioA * a.y + ratioB * b.y;
28         out.z = ratioA * a.z + ratioB * b.z;
29         out.w = ratioA * a.w + ratioB * b.w;
30         out.normalizeInPlace();
31         return out;
32     }

 

以上是关于ARCore中四元数的插值算法实现的主要内容,如果未能解决你的问题,请参考以下文章

ARCore中Pose类变换点的算法实现

Unity编程Unity中关于四元数的API详解

如何理解glm中四元数与向量相乘函数的写法

SLAM练习题(十三)—— 四元数插值

四元数旋转

eigen 中四元数欧拉角旋转矩阵旋转向量