没有欧拉角的四元数旋转 [英] Quaternion rotation without Euler angles

查看:27
本文介绍了没有欧拉角的四元数旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此评论中,强烈建议我们永远不要使用欧拉角.我知道欧拉角有一些限制,最明显的是万向节锁,但我想知道最好的技术,或一组技术,在没有欧拉角的情况下通常使用什么?

In this comment it was strongly suggested that we should never use Euler angles. I understand that there are some limitation to Euler angles, most notably gimbal lock, but I'd like to know the best technique, or the set of techniques, that one typically uses in the absence of Euler angles?

关于这个主题的大多数讨论都涉及从欧拉角转换为四元数,这是一件很简单的事情.但我读过的关于在没有欧拉角的情况下进行旋转的唯一方法是从两个向量创建四元数,如 Stan Melax 在Game Programming Gems"中的文章The Shortest Arc Quaternion"中所述,使用这种技术:

Most dicussions on this topic involve converting from an Euler angle to a quaternion and that is a simple thing to do. But the only way I have ever read about doing rotation without Euler angles at all is to create a quaternion from two vectors as described by the article "The Shortest Arc Quaternion" by Stan Melax in "Game Programming Gems", using this technique:

template <typename T>
inline QuaternionT<T> QuaternionT<T>::CreateFromVectors(const Vector3<T>& v0, const Vector3<T>& v1)
{

    Vector3<T> c = v0.Cross(v1);
    T d = v0.Dot(v1);
    T s = std::sqrt((1 + d) * 2);

    QuaternionT<T> q;
    q.x = c.x / s;
    q.y = c.y / s;
    q.z = c.z / s;
    q.w = s / 2.0f;
    return q;
}

这是链接评论中提到的方法吗?

Is this the method referred to in the linked comment?

推荐答案

Orientation

方向是变换在坐标系内定向对象的方式.方向是一个绝对量,如位置或标量.方向在概念上是一个值.并且有一些操作可以应用于方向,具体取决于它们的表示.

Orientation

An orientation is the way that a transform will orient an object within a coordinate system. An orientation is an absolute quantity, like a position or a scalar. An orientation is conceptually a value. And there are operations one can apply to orientations, depending on their representation.

与向量和标量不同,方向可以用多种方式表示.

Unlike vectors and scalars, orientations can be represented in a wide variety of ways.

欧拉角是围绕 3 个固定的正交轴旋转 3 次的系列.这些应用的顺序很重要,通常是按惯例确定的.

Euler angles are a series of 3 rotations about 3 fixed, orthogonal axes. The order in which these are applied is important and is generally established by convention.

使用欧拉角"意味着欧拉角是您的代码存储和操作对象方向的方式.您最终如何组合这些角度以生成矩阵无关紧要.重要的是您的代码会将方向视为 3 个角度.例如,当您对方向应用旋转偏移时,它将作为旋转角度的偏移提供,这些偏移将直接应用于存储的欧拉角.

To "use Euler angles" means that Euler angles are how your code stores and manipulates the orientation of an object. How you eventually compose these angles to generate a matrix is of no consequence. What matters is that your code will treat the orientation as 3 angles. For example, when you apply a rotational offset to the orientation, it will be provided as offsets to rotation angles, and these offsets will be applied to the stored Euler angles directly.

我知道没有人这么说过,但我有一点要说明.

I know nobody said that, but I have a point to make here.

使用矩阵"意味着旋转矩阵是您的代码存储和操作对象方向的方式.如果某段代码想要旋转对象,他们将在左侧或右侧应用一个矩阵.即使该矩阵是通过一些轴向旋转计算的,代码仍然在矩阵上执行基本操作,而不是角度.

To "use matrices" means that a rotation matrix is how your code stores and manipulates the orientation of an object. If some piece of code wants to rotate the object, they will apply a matrix to it, either on the left side or the right. Even if that matrix is computed via some axial rotation, the code is still performing the basic operation on a matrix, not an angle.

出于本次讨论的目的,四元数"是用于对方向进行编码的 4 元素单位向量.四元数可以对它们进行类似矩阵的操作,例如组合和求逆.四元数必须保持标准化才能正确编码方向.

For the purposes of this discussion, a "quaternion" is a 4-element unit vector which is used to encode an orientation. Quaternions can have matrix-like operations done on them, such as composition and inversion. Quaternions must remain normalized in order to properly encode an orientation.

使用四元数"意味着您将对象的方向和操作存储为四元数.在最基本的层面上,您对方向的所有操作都涉及四元数数学.

To "use quaternions" means that you are storing the orientation and manipulating of the object as a quaternion. All of your operations on orientations, at their most fundamental level, are dealing with quaternion math.

欧拉角经常被使用,因为它们(理论上)可以直观地进行调整:您只需增加或减少一个角度.如果要在 X 方向上将对象旋转 -10 度,只需从 X 轴旋转中减去 10.但是我们不想使用它们,因为它们很糟糕,所以让我们看看其他方向表示.

Euler angles are often used because they are (theoretically) intuitive to adjust: you just increment or decrement an angle. If you want to turn the object -10 degrees in the X, you just subtract 10 from the X axial rotation. But we don't want to use them, because they're terrible, so let's look at the other orientation representations.

要将方向调整为矩阵,您必须做两件事.您必须将当前方向与偏移旋转矩阵相乘(如果要在 X 轴上旋转 -10 度,请为此创建一个角度/轴矩阵并将其右乘).然后,由于计算机的精度有限,您必须重新对矩阵进行正交化.如果你不做第二步,你的矩阵最终将不再是正交的,从而不再是一个方向.

To adjust an orientation as a matrix, you have to do two things. You must multiply the current orientation with an offset rotation matrix (if you want to rotate by -10 degrees in the X axis, you create an angle/axis matrix for that and right-multiply it). And then, because computers have finite precision, you must re-orthonormalize the matrix. If you don't do the second step, your matrix will eventually stop being orthonormal and thus stop being an orientation.

对矩阵进行正交归一化很困难.这就是我们使用四元数的(部分)原因.归一化四元数很容易;它只是 4 元素向量归一化.由于四元数和矩阵具有类似的运算,因此相同的数学运算适用于两者.所以它们看起来几乎一模一样.

Orthonormalizing a matrix is hard. That's (part of) the reason why we use quaternions instead. Normalizing a quaternion is easy; it's just 4-element vector normalization. And since quaternions and matrices have analogous operations, the same math will work with both. So they look pretty much identical.

这篇关于没有欧拉角的四元数旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆