码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-09-05 18:58:49      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:ted   abs   int   out   new   oat   div   code   core   

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中四元数的插值算法实现

标签:ted   abs   int   out   new   oat   div   code   core   

原文地址:http://www.cnblogs.com/calence/p/7479867.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!