Today I coded the multiplication of quaternions and vectors in Java. This is less of a coding question and more of a math question though:
Quaternion a = Quaternion.create(0, 1, 0, Spatium.radians(90));
Vector p = Vector.fromXYZ(1, 0, 0);
System.out.println(a + " * " + p + " = " + Quaternion.product(a, p));
System.out.println(a + " * " + p + " = " + Quaternion.product2(a, p));
What I am trying to do is rotate a point $\mathbf{p}$ using the quaternion $\mathbf{q}$. The functions product()
and product2()
calculate the product in two different ways, so I am quite certain that the output is correct:
(1.5707964 + 0.0i + 1.0j + 0.0k) * (1.0, 0.0, 0.0) = (-1.0, 0.0, -3.1415927)
(1.5707964 + 0.0i + 1.0j + 0.0k) * (1.0, 0.0, 0.0) = (-1.0, 0.0, -3.1415927)
However, I can't wrap my head around why the result is the way it is. I expected to rotate $\mathbf{p}$ 90 degrees around the y-axis, which should have resulted in (0.0, 0.0, -1.0)
.
Wolfram Alpha's visualization also suggests the same: https://www.wolframalpha.com/input/?i=(1.5707964+%2B+0.0i+%2B+1.0j+%2B+0.0k)
So what am I doing wrong here? Are really both the functions giving invalid results or am I not understanding something about quaternions?