Search code examples
mathmatrix3dquaternionsrotational-matrices

Fast Quaternion-Vector Multiplication with other Transformation Matrices


I am currently trying to find an equivalent for the following equation:

vec_res = inverse(VM) * (q * (VM * vec_input) * conjugate(q))

where VM is a standard view matrix , q is a normalized quaternion, and vec_input a vector.

In the form:

vec_res = A * vec_input;

or

vec_res = q' * vec_input * conjugate(q');

From https://molecularmusings.wordpress.com/2013/05/24/a-faster-quaternion-vector-multiplication/ I am already calculating

vec_res = inverse(VM) * q * VM * vec_input * conjugate(q)

as

pN = (VM * vec_input);
vec3 tempVec = 2.0 * cross(q.xyz, pN);
pN = pN + q.w * tempVec + cross(q.xyz, tempVec);
pN = inverse(VM) * pN;

My question is, do I have the right to rewrite the equation like this ?

vec_res = (inverse(VM) * conversion_to_matrix(q) * VM) * vec_input

Where conversion_to_matrix is the rotation matrix calculated as explained in: http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToMatrix/

If no, what is the math to be used behind ?


Solution

  • vec_res = (inverse(VM) * conversion_to_matrix(q) * VM) * vec_input
    

    Is perfectly valid. The problem is...

    inverse(VM) * conversion_to_matrix(q) * VM
    

    is NOT equal to

    conversion_to_matrix(q)
    

    Therefore you have to keep the original equation in its entirety.