Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate Quaternion by an offset?

I'm trying to add an offset to the rotation of a quaternion, according to the Unity documentation multiplying two Quaternions is the same as doing both rotations in sequence.

This is what I'm trying now:

If the offset Quaternion is (0, 0, 0, 0) multiplying the first quaternion by it, shouldn't have any effect. However in my tests multiplying any Quaternion by (0, 0, 0, 0) results in (0, 0, 0, 0), so this is not working correctly.

    Quaternion q = new Quaternion (-0.7f, 0f, 0f, -0.7f);
    Quaternion rotationZero = new Quaternion (0f, 0f, 0f, 0f); // offset

    Quaternion result = q * rotationZero;

    print (result); // (0.0, 0.0, 0.0, 0.0)
like image 957
lisovaccaro Avatar asked Oct 20 '25 02:10

lisovaccaro


1 Answers

Here the issue is not is C# or in Unity, the values you are using causes the output values to be (0.0, 0.0, 0.0, 0.0). It can be mathematically explained as below.

The quaternions have the form of

q = q0 + iq1 + jq2 + kq3 and r = r0 + ir1 + jr2 + kr3

The quaternion product has the form of

t= q×r = t0 + it1 + jt2 + kt3, where

t0 = (r0q0−r1q1−r2q2−r3q3) t1 = (r0q1+r1q0−r2q3+r3q2) t2 = (r0q2+r1q3+r2q0−r3q1) t3 = (r0q3−r1q2+r2q1+r3q0)

like image 173
Dinal24 Avatar answered Oct 22 '25 03:10

Dinal24



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!