Flipping a quaternion from right to left handed co

2019-02-12 22:03发布

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

to left handed coordinates where:
x = left to right
y = top to bottom
z = front to back

How would I go about doing this?

标签: math 3d
5条回答
混吃等死
2楼-- · 2019-02-12 22:23

I think that the solution is:

Given:    Right Hand: {w,x,y,z}
Option 1: Left Hand: {y,-z,-w,-x}
Option 2: Left Hand: {-y,z,w,x} (equivalent)
查看更多
放荡不羁爱自由
4楼-- · 2019-02-12 22:35

Ok, just to be clear, quaternions don't actually have handedness. They are handless(see wikipedia article on quaternions). HOWEVER, the conversion to a matrix from a quaternion does have handedness associated with it. See http://osdir.com/ml/games.devel.algorithms/2002-11/msg00318.html If your code performs this conversion, you may have to have two separate functions to convert to a left handed matrix or a right handed matrix.

Hope that helps.

查看更多
来,给爷笑一个
5楼-- · 2019-02-12 22:41

Once you do that, you no longer have a quaternion, i.e. the usual rules for multiplying them won't work. The identity i^2 = j^2 = k^2 = ijk = -1 will no longer hold if you swap j and k (y and z in your right handed system).

查看更多
不美不萌又怎样
6楼-- · 2019-02-12 22:43

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

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.

These things are true:

  • 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) and a mirroring about some axis.

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

mat3x3 rosToUnity = /* construct this by hand */;
mat3x3 unityToRos = rosToUnity.inverse();
quat q_ros = ...;
mat3x3 m_unity = rosToUnity * mat3x3(q_ros) * unityToRos;
quat q_unity = quat(m_unity);

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.

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 unityToRos and rosToUnity both have determinant -1 (as a result of the handedness switch).

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.

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

查看更多
登录 后发表回答