来自两个向量对的四元数 [英] Quaternion from two vector pairs
问题描述
我有两个向量对(旋转前后).
I have two vector pairs (before and after rotation).
旋转前:[x1,y1,z1][x2,y2,z2]
before rotation: [x1,y1,z1] [x2,y2,z2]
旋转后:[x1',y1',z1'][x2',y2',z2']
after rotation: [x1',y1',z1'] [x2',y2',z2']
如何创建表示此旋转的四元数?
How to create a quaternion representing this rotation?
推荐答案
在大多数情况下,没有将 2 个向量转换为 2 个其他向量的旋转.这是一个简单的方法来形象化原因:旋转不会改变向量之间的角度.如果旋转前 2 个向量之间的角度与旋转后 2 个向量之间的角度不同,则不存在符合条件的旋转.
In most cases there is no rotation which transforms 2 vectors into 2 other vectors. Here is a simple way to visualize why: a rotation does not change the angle between vectors. If the angle between the 2 vectors before the rotation is different from the angle between the 2 vectors after the rotation, then there is no rotation which meets your criteria.
这表示可能存在具有可接受误差的最佳四元数,它几乎"旋转了您的 2 个向量对.有许多算法在速度和精度上各不相同,可以找到这样的四元数.我为 Arduino 应用程序编写了一个快速的 C++ 算法,其中速度很重要,但精度不太重要.
This said there may be an optimal quaternion with an acceptable error which "almost" rotates your 2 vector pairs. There are a number of algorithms which vary in speed and precision to find such a quaternion. I wrote a fast C++ algorithm for an Arduino application where the speed is critical but the precision is less important.
旋转前:u0,v0.旋转后:u2,v2.
Before rotation: u0, v0. After rotation: u2, v2.
Quaternion q2 = Quaternion::fromTwoVectors(u0, u2);
Vector v1 = v2.rotate(q2.conjugate());
Vector v0_proj = v0.projectPlane(u0);
Vector v1_proj = v1.projectPlane(u0);
Quaternion q1 = Quaternion::fromTwoVectors(v0_proj, v1_proj);
return (q2 * q1).normalized();
如果这不符合您自己的应用程序的要求,请尝试 google Wabha 的问题.
If this does not meet the requirements of your own application try to google Wabha's problem.
这篇关于来自两个向量对的四元数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!