Handedness in Quaternion multiplication

1.1k Views Asked by At

I've received some code (which I didn't write) and decided at some point to write test cases for the Quaternion math implementation.

I used Wolfram alpha to get the result q1 * q2, where:

q1 = (4.0 + 1.0i + 2.0j + 3.0k)

q2 = (8.0 - 5.0i + 6.0j - 7.0k)

Wolfram alpha calculates the result to be (46 - 44i + 32j + 12k)

My code calculates the result to be (46 + 20i + 48j - 20k)

This is not equal to Wolfram Alpha's calculation of q1 * q2 (which meant my test failed), but interestingly, it's equal to q2 * q1.

Similarly, q2 * q1 calculated by my code is equal to Wolfram Alpha's result of q1 * q2

Normally I would think that my multiplication function is performed incorrectly, but the function is used several times in the program with correct results.

I was wondering if this is considered a bug, or just a design choice. Is this quaternion multiplication performed in a "left-handed" manner, compared to the norm, which uses right handed math? I do know that handedness matters for rotation matrices, but I haven't read anything about Quaternions. Is there another explanation for this?

2

There are 2 best solutions below

0
On BEST ANSWER

It sounds like your multiplication function is actually trying to give the net quaternion for a composition of rotations. That is, you have a function mult(q1, q2) that finds the net quaternion qnet corresponding to a rotation by q1 first and q2 subsequent to that.

More explicitly, if the quaternion $q_1$ corresponds to a rotation map $R_1$, then for any vector $a$ (which we represent as a pure imaginary quaternion), the rotation takes the form

$$R_1(a) = q_1 a q_1^{-1}$$

And if you have another rotation $R_2$ associated with a quaternion $q_2$, then the whole rotation takes the form

$$R_2 R_1(a) = q_2 q_1 a q_1^{-1} q_2^{-1}$$

So the net quaternion of the rotation is $q_\text{net} = q_2 q_1$.

Still, I consider it a somewhat easy trap to write the multiplication function to switch left and right in this way, convenient though it may be to keep track of which rotation is "first".

1
On

That's a complicated test. You should be testing the three multiplications $ij, jk, ki$, which determine everything else. The standard conventions are that these should be $k, i, j$ respectively (the same as the standard convention for the cross product). You can use the opposite convention, that instead we should have $ji, kj, ij$ be equal to $k, i, j$ respectively, but you get the same ring, just with a differently labeled basis of it (more or less).

This is special to the quaternions. In general, if $R$ is a ring, there is another ring we can construct from it called its opposite ring $R^{op}$, which has the same addition as $R$ but which has reversed multiplication: that is,

$$a \times^{op} b = b \times a$$

where $\times$ refers to multiplication in $R$ and $\times^{op}$ refers to multiplication in $R^{op}$. If $R$ is commutative then nothing has changed. If $R$ is noncommutative then it can sometimes happen that $R$ and $R^{op}$ are still isomorphic. This is true for the quaternions $\mathbb{H}$, where the isomorphism takes the form

$$\mathbb{H} \ni a + bi + cj + dk \mapsto a - bi - cj - dk \in \mathbb{H}^{op}.$$

However, it is not true in general, not even for division algebras.