将四元数从右手坐标系转换为左手坐标系

时间:2015-02-23 12:24:43

标签: math graphics 3d

我的3d程序,对象的旋转由四元数表示,如[0.130526, 0.0, 0.0, 0.991445]。该程序使用右手坐标系,Z轴朝上(如3ds max):

enter image description here

另一方面,我的应用程序使用左手坐标系,Y轴向上

enter image description here

如何将四元数从一个坐标系转换为另一个坐标系,并考虑哪个轴已经到位?

2 个答案:

答案 0 :(得分:12)

围绕轴(u,v,w)的角度x的旋转可以用实部cos(x / 2)和虚部sin(x / 2)*(u,v,w)的四元数表示。 / p>

如果原始三面体中的轴坐标为(u,v,w),则它们将在您的三面体中为(u,w,v)。

因此,如果原始四元数是(a,b,c,d) - a + ib + jc + kd - 四元数必须转换为三面体中的(a,b,d,c)。

修改

但是因为你的三面体是左撇子,所以角度也必须颠倒,所以最终可以用你的三面体中的四元数(a,-b,-d,-c)表示相同的旋转。

答案 1 :(得分:0)

This is a condensed version of an answer to a slightly different question.

The problem you ask about arises even if the two coordinate systems are same-handed; it turns out that handedness flips don't make the problem significantly harder. Here is how to do it in general. To change the basis of a quaternion, say from ROS (right-handed, Z up) to Unity (left-handed, Y up):

mat3x3 ros_to_unity = /* construct this by hand by mapping input axes to output axes */;
mat3x3 unity_to_ros = ros_to_unity.inverse();
quat q_ros = ...;
mat3x3 m_unity = ros_to_unity * mat3x3(q_ros) * unity_to_ros;
quat q_unity = mat_to_quat(m_unity);

Lines 1-4 are simply the method of https://stackoverflow.com/a/39519079/194921: "How do you perform a change-of-basis on a matrix?"

Line 5 is interesting; not all matrices convert to quats, but if ros_to_unity is correct, then this conversion will succeed.

Note that this will give you a correct result, but it goes through a lot of work -- conversion to and from a matrix, some multiplies, an inversion. But you can examine its results and then write a special-case version that rearranges or flips axes, like the one aka.nice derived.