将四元数从右手坐标翻转到左手坐标 [英] Flipping a quaternion from right to left handed coordinates

查看:30
本文介绍了将四元数从右手坐标翻转到左手坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从右边翻转一个四元数:
<代码>x = 从左到右
y = 从前到后
z = 从上到下

I need to flip a quaternion from right:
x = left to right
y = front to back
z = top to bottom

到左手坐标,其中:
<代码>x = 从左到右
y = 从上到下
z = 从前到后

我该怎么做?

推荐答案

我认为这些答案都不正确.

I don't think any of these answers is correct.

Andres 认为四元数没有手性 (*) 是正确的.惯用手(或我称之为轴惯例")是人类应用的属性;这就是我们如何将向前、向右、向上"的概念映射到 X、Y、Z 轴.

Andres is correct that quaternions don't have handedness (*). Handedness (or what I'll call "axis conventions") is a property that humans apply; it's how we map our concepts of "forward, right, up" to the X, Y, Z axes.

这些都是真的:

  • 纯旋转矩阵(正交、行列式 1 等)可以转换为单位四元数并返回,从而恢复原始矩阵.
  • 纯旋转矩阵(行列式为 -1 的矩阵,例如翻转单个轴的矩阵)也称为不正确旋转",不能转换为单位四元数和背部.你的 mat_to_quat() 例程可能不会崩溃,但它不会给你正确的答案(在 quat_to_mat(mat_to_quat(M)) == M 的意义上).
  • 交换惯用手的基数变化具有行列式 -1.这是一个不正确的旋转:相当于一个由关于原点的镜像组成的旋转(可能是身份).
  • Pure-rotation matrices (orthogonal, determinant 1, etc) can be converted to a unit quaternion and back, recovering the original matrix.
  • Matrices that are not pure rotations (ones that have determinant -1, for example matrices that flip a single axis) are also called "improper rotations", and cannot be converted to a unit quaternion and back. Your mat_to_quat() routine may not blow up, but it won't give you the right answer (in the sense that quat_to_mat(mat_to_quat(M)) == M).
  • A change-of-basis that swaps handedness has determinant -1. It is an improper rotation: equivalent to a rotation (maybe identity) composed with a mirroring about the origin.

要改变四元数的基,比如从 ROS(右手)到 Unity(左手),我们可以使用 .

To change the basis of a quaternion, say from ROS (right-handed) to Unity (left-handed), we can use the method of .

mat3x3 ros_to_unity = /* construct this by hand */;
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);

第 1-4 行只是 https://stackoverflow.com/a/39519079/194921 的方法:您如何对矩阵执行基变换?"

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?"

第 5 行很有趣.我们知道 mat_to_quat() 仅适用于纯旋转矩阵.我们怎么知道 m_unity 是一个纯旋转?当然可以想象它不是,因为 unity_to_rosros_to_unity 都有行列式 -1(作为惯用手切换的结果).

Line 5 is interesting. We know mat_to_quat() only works on pure-rotation matrices. How do we know that m_unity is a pure rotation? It's certainly conceivable that it's not, because unity_to_ros and ros_to_unity both have determinant -1 (as a result of the handedness switch).

hand-wavy 的答案是,左撇子切换了两次,所以结果没有左撇子切换.更深层次的答案与相似变换保留了运算符的某些方面有关,但我没有足够的数学来证明.

The hand-wavy answer is that the handedness is switching twice, so the result has no handedness switch. The deeper answer has to do with the fact that similarity transformations preserve certain aspects of the operator, but I don't have enough math to make the proof.

注意,这会给你一个正确的结果,但如果 unity_to_ros 是一个简单的矩阵(比如,只有一个轴交换),你可能可以更快地完成它.但是您可能应该通过扩展此处完成的数学来推导出更快的方法.

Note that this will give you a correct result, but you can probably do it more quickly if unity_to_ros is a simple matrix (say, with just an axis swap). But you should probably derive that faster method by expanding the math done here.

(*) 其实Hamilton和JPL四元数是有区别的;但每个人都使用汉密尔顿,所以没有必要用它来搅浑水.

(*) Actually, there is the distinction between Hamilton and JPL quaternions; but everybody uses Hamilton so there's no need to muddy the waters with that.

这篇关于将四元数从右手坐标翻转到左手坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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