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

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

问题描述

在<一个href="http://stackoverflow.com/questions/12206908/glm-matrix-from-orientation-is-creating-row-major-and-not-column-major-matrix#comment16350007_12206908">this评论它强烈建议我们不应该使用欧拉角。据我所知,有一些限制欧拉角,最显着的万向节锁定,但我想知道最好的技术,或者组技术,即人们通常在没有欧拉角的使用?大多数dicussions关于这一主题涉及从欧拉角转换为四元数,这是一个简单的事情。但是,我曾经读到这样的旋转没有欧拉的唯一途径角度都为创建两个向量的四元数,如游戏编程精粹中描述的文章最短弧四元数由斯坦Melax,使用此技术:

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? Most dicussions on this topic involve converting from a 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?

推荐答案

这是取向是一个变换将定向的坐标系内的对象的方式。一个方向是绝对量,如位置或标量。的取向是概念上的值。和有操作的一个可应用于定向,这取决于它们的重presentation

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.

不同于矢量和标量,方位可以重新psented在一个多种方式$ P $

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.

要用欧拉角是​​指欧拉角是多么的code存储和处理的对象的方向。如何你最终撰写这些角度来生成矩阵是没有结果的。重要的是,你的code将把定向为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.

要使用矩阵是指一个旋转矩阵是如何使你的code存储和处理的对象的方向。如果某些块的code要旋转对象,他们将一个矩阵适用于它,无论是在左侧或右侧。即使该矩阵是通过一些轴向旋转计算,则code为依然表现上的基本动作的的矩阵的,而不是一个角度。

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.

有关此讨论的目的,一个四元数是用于连接到code的方向的4元件单位向量。四元数可以对它们进行基质样操作,如组合物和反演。四元数必须为了保持规范化正确连接$ C C的方向$。

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.

欧拉角经常使用,因为它们是(理论上)直观地调整:你只是增加或减少的角度。如果您想将对象-10度的X,你只减去10从X轴旋转。但我们不希望使用他们,因为他们是可怕的,所以让我们看看其他的方向再presentations。

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度旋转,您创建的和右乘以它的角度/轴矩阵)。然后,因为电脑有有限precision,你必须重新orthonormalize矩阵。如果你不这样做的第二个步骤,你的矩阵最终将不再是正交的,因而不再是一个的取向的。

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.

Orthonormalizing矩阵是很难的。这是(部分)为什么我们使用四元数,而不是原因。归一四元数是容易的;它只是4元向量正常化。而且,由于四元数和矩阵具有类似的操作,同样的数学将与这两个。因此,他们期待pretty的很多是相同的。

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天全站免登陆