Search code examples
c++seriesquaternions

Series of Quaternions


Please excuse my ignorance on quaternions (trying to learn them as I type this). In the context of 3D graphics, suppose I have a point p1 which gets transformed by a series of quaternions from q0 to qn yielding to point p2. Knowing all the quaternions to get from p1 to p2, is it possible to do the reverse to get back to p1?

I tried something silly like this but it didn't give me what I was after:

int main(void)
{
    vmath::vec4 p1(4.0f, 3.0f, 2.0f, 1.0f);
    print_vec4(p1);

    vmath::quaternion q1(1.0f, 0.0f, 0.0f, M_PI);
    vmath::vec4 p2 = p1 * q1.asMatrix();
    print_vec4(p2);

    vmath::quaternion q2(q1);
    q2 = q2.conjugate();
    p2 = p2 * q2.asMatrix();
    print_vec4(p2);

    return 0;
}

Solution

  • T = q1 * q2 *...qn the inverse transform to this one is T^-1 = qn^-1 .. * q2^-1 * q1^1; where "^1" mean "inverse", for unit length quaternion we can reverse sign of "vector" (x,y,z) components for inverse operation.

    And at least

    p2 = T * p1; and p1 = T^-1 * p2