"unit" 四元数和 "identity" 四元数有什么区别?

What is the difference between a "unit" quaternion and an "identity" quaternion?

我一直在使用 www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/ 上的指南来学习 OpenGL。本指南说...

glm::quat q;

...creates an identity quaternion (no rotation).

实验表明 q = [0, 0, 0, 0]。将其用作根骨骼的 parent 方向会导致 none 的骨骼完全旋转。他们失去了所有旋转。

导游说...

A quaternion is a set of 4 numbers, [x y z w], which represents rotations the following way:

// RotationAngle is in radians

x = RotationAxis.x * sin(RotationAngle / 2)

y = RotationAxis.y * sin(RotationAngle / 2)

z = RotationAxis.z * sin(RotationAngle / 2)

w = cos(RotationAngle / 2)

...和...

[0 0 0 1] (w=1) means that angle = 2*acos(1) = 0, so this is a unit quaternion, which makes no rotation at all.

我一直在试验一个骨架系统,其中每个骨骼都继承其 parents 的方向,然后在其上应用自己的旋转。

如果我使用 "identity" 四元数作为根骨骼的 "parent" 方向,那么 none 的骨骼将完全旋转。如果我使用 "unit" 旋转,一切都很好。

当我将骨骼的初始方向设置为 "identity" 或 "unit" 四元数时,它会按照我的意愿显示。但是,当我将用户输入的欧拉角转换为方向时,我得到了 180 度的旋转。我所做的转换是:

        glm::vec3 eulers(glm::radians(pose.lng_rotate),
                         glm::radians(pose.lat_rotate),
                         glm::radians(pose.att_rotate));

        pose.orientation = glm::quat(eulers);

注意:我在这里使用 "lng"、"lat" 和 "att" 旋转,因为当骨骼继承 parent 旋转时 "x" axis 可能不再是 "x" 轴了。

我注意到的最后一件奇怪的事情是我在每种类型的四元数上使用了 glm::mat4_cast,然后乘以一个恒等式 glm::vec4。 "identity" 四元数使向量保持不变,但 "unit" 四元数导致向量反转(乘以 -1)向量的 x 和 y 分量。

我想更好地理解四元数,尤其是它们在代码中的使用。

从概念上讲,"unit" 四元数与 "identity" 四元数有何不同?

我应该在哪里使用"unit"四元数以及我应该在哪里使用"identity"四元数?

我只是被写得不好的指南弄糊涂了吗?

单位四元数和恒等四元数是一回事。该指南写得不好,令人困惑。

glm::quat q; NOT 创建恒等四元数。它创建了一个无效的四元数。创建恒等四元数的最佳方法是 glm::quat q(glm::vec3(0.0, 0.0, 0.0));glm::quat q(1.0, 0.0, 0.0, 0.0);。第一个基于所有零欧拉旋转的向量生成四元数。第二个明确地将其初始化为身份四元数。

请注意,虽然四元数通常被描述为 [x y z w],但它们被存储和初始化为 (w, x, y, z)

单位四元数与恒等四元数不同。四元数就是 'quaternion space' 中的任何数字,例如 3 + 2i - 7j + 6k.

当我们使用四元数计算旋转时,我们总是在谈论单位四元数并且长度始终为 1,就像单位向量一样。单位四元数相乘是计算旋转的一种非常有效的方法,但长度必须保持不变,1.

恒等四元数是不改变与其相乘的任何四元数的四元数,因此 1 + 0i + 0j + 0k1。因此,恒等四元数是无的旋转。