为什么四元数用于旋转? [英] Why are quaternions used for rotations?

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

问题描述

我是一名物理学家,一直在学习一些编程,并且遇到过很多人使用四元数进行旋转而不是以矩阵/向量形式编写东西.

I'm a physicist, and have been learning some programming, and have come across a lot of people using quaternions for rotations instead of writing things in matrix/vector form.

在物理学中,我们有充分的理由不使用四元数(尽管偶尔会讲到关于 Hamilton/Gibbs/等的奇怪故事).物理学要求我们的描述具有良好的分析行为(这具有精确定义的含义,但在某些相当技术性的方式上远远超出了正常介绍课程中所教授的内容,因此我不会详细介绍).事实证明,四元数没有这种好的行为,所以它们没有用,向量/矩阵有,所以我们使用它们.

In physics, there are very good reasons we don't use quaternions (despite the bizarre story that's occasionally told about Hamilton/Gibbs/etc). Physics requires that our descriptions have good analytic behavior (this has a precisely defined meaning, but in some rather technical ways that go far beyond what's taught in normal intro classes, so I won't go into any detail). It turns out that quaternions don't have this nice behavior, and so they aren't useful, and vectors/matrices do, so we use them.

但是,仅限于不使用任何解析结构的刚性旋转和描述,3D 旋转可以用任何一种方式(或其他几种方式)等价地描述.

However, restricted to rigid rotations and descriptions that do not use any analytic structures, 3D rotations can be equivalently described either way (or a few other ways).

一般来说,我们只想要一个点 X = (x, y, z) 到一个新点 X' = (x', y', z') 的映射,受 X2 = X'2.有很多事情可以做到这一点.

Generally, we just want a mapping of a point X = (x, y, z) to a new point X' = (x', y', z') subject to the constraint that X2 = X'2. And there are lots of things that do this.

最简单的方法是绘制这个定义的三角形并使用三角函数,或者使用点 (x, y, z) 和向量 (x, y, z) 之间的同构和函数 f(X) =X' 和矩阵 MX = X',或使用四元数,或使用其他方法 (x, y, z)T.(a,b,c) (x',y',z') 等

The naive way is to just draw the triangles this defines and use trigonometry, or use the isomorphism between a point (x, y, z) and a vector (x, y, z) and the function f(X) = X' and a matrix MX = X', or using quaternions, or projecting out components of the old vector along the new one using some other method (x, y, z)T.(a,b,c) (x',y',z'), etc.

从数学的角度来看,这些描述在这个设置中都是等价的(作为一个定理).它们都具有相同数量的自由度、相同数量的约束等.

From a math point of view, these descriptions are all equivalent in this setting (as a theorem). They all have the same number of degrees of freedom, the same number of constraints, etc.

那么为什么四元数似乎比向量更受欢迎?

So why do quaternions seem to preferred over vectors?

我看到的通常原因是没有万向节锁定或数字问题.

The usual reasons I see are no gimbal lock, or numerical issues.

无万向节锁定的说法似乎很奇怪,因为这只是欧拉角的问题.它也只是一个坐标问题(就像极坐标中r=0处的奇点(雅可比松散秩)),也就是说它只是一个局部问题,可以通过切换坐标,旋转出简并来解决,或使用两个重叠的坐标系.

The no gimbal lock argument seems odd, since this is only a problem of euler angles. It is also only a coordinate problem (just like the singularity at r=0 in polar coordinates (the Jacobian looses rank)), which means it is only a local problem, and can be resolved by switching coordinates, rotating out of the degeneracy, or using two overlapping coordinate systems.

我对数字问题不太确定,因为我不知道这两个(以及任何替代方案)将如何实施的详细信息.我读过重新归一化四元数比对旋转矩阵进行重新归一化更容易,但这仅适用于一般矩阵;旋转有额外的约束,使这个变得微不足道(这些约束内置在四元数的定义中)(事实上,这必须是真的,因为它们具有相同数量的自由度).

I'm less sure about numerical issues, since I don't know in detail how both of these (and any alternatives) would be implemented. I've read that re-normalizing a quaternion is easier than doing that for a rotation matrix, but this is only true for a general matrix; a rotation has additional constraints that trivializes this (which are built into the definition of quaternions) (In fact, this has to be true since they have the same number of degrees of freedom).

那么使用四元数代替向量或其他替代方法的原因是什么?

So what is the reason for the use of quaternions over vectors or other alternatives?

推荐答案

万向节锁是一个原因,虽然正如你所说,这只是欧拉角的问题,很容易解决.当您只需要存储 3 个数字时,仍然会使用欧拉角,因为您只需要存储 3 个数字.

Gimbal lock is one reason, although as you say it is only a problem with Euler angles and is easily solvable. Euler angles are still used when memory is a concern as you only need to store 3 numbers.

对于四元数与 3x3 旋转矩阵,四元数在大小(4 个标量与 9 个标量)和速度(四元数乘法比 3x3 矩阵乘法快得多)方面具有优势.

For quaternions versus a 3x3 rotation matrix, the quaternion has the advantage in size (4 scalars vs. 9) and speed (quaternion multiplication is much faster than 3x3 matrix multiplication).

请注意,所有这些旋转表示都在实践中使用.欧拉角使用最少的内存;矩阵使用更多内存,但不会受到万向节锁定的影响并且具有很好的分析特性;和四元数在两者之间取得了很好的平衡,重量轻,但没有万向节锁定.

Note that all of these representations of rotations are used in practice. Euler angles use the least memory; matrices use more memory but don't suffer from Gimbal lock and have nice analytical properties; and quaternions strike a nice balance of both, being lightweight, but free from Gimbal lock.

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

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