title: Combining quaternions with different pivot point
body: <h2>Background:</h2>
  
  <p>I am currently implementing a skeletal animation shader in GLSL, and to save space and complexity I am using Quaternions for the bone rotations, using weighted quaternion multiplication (of each bone) to accumulate a "final rotation" for each vertex.</p>
  
  <p>Something like: (pseudo-code, just assume the quaternion math works as expected)</p>
  
  <pre><code>  float weights[5];
    int bones[5];
    vec4 position;
  
    uniform quaternion allBoneRotations[100];
    uniform vec3 allBonePositions[100];
  
    main(){
    quaternion finalQuaternion;
    for(i=0;i&lt;5;i++){finalQuaternion *= allBoneRotations[bones[i]]*weights[i];}
    gl_position = position.rotateByQuaternion(finalQuaternion);
    }
  </code></pre>
  
  <p>The real code is complicated, sloppy, and working as expected, but this should give the general idea, since this is mostly a math question anyway, the code isn't of much consequence, it's just provided for clarity.</p>
  
  <h2>Problem:</h2>
  
  <p>I was in the process of adding "pivot points"/"joint locations" to each bone (negative translate, rotate by "final quaternion", translate back) when I realized that the "final quaternion" will not have taken the different pivot points into account when combining the quaternions themselves. In this case each bone rotation will have been treated as if it was around point (0,0,0).</p>
  
  <p>Given that quaternions represent only a rotation, it seems I'll either need to "add" a position to the quaternions (if possible), or simply convert all of the quaternions into matrices, then do matrix multiplication to combine the series of translations and rotations. I am really hoping the latter is not necessary, since it seems like it would be really inefficient, comparatively.</p>
  
  <p>I've searched through mathoverflow, math.stackexchange, and whatever else Google provided and read the following resources so far in hopes of figuring out an answer myself:</p>
  
  <ul>
  <li><p><a href="http://shankel.best.vwh.net/QuatRot.html">http://shankel.best.vwh.net/QuatRot.html</a></p></li>
  <li><p><a href="http://mathworld.wolfram.com/Quaternion.html">http://mathworld.wolfram.com/Quaternion.html</a></p></li>
  <li><p>plus various other small discussions found through Googling (I can only post 2 links)</p></li>
  </ul>
  
  <p>The consensus is that Quaternions do not encode "translation" or "position" in any sense, and don't seem to provide an intuitive way to simulate it, so pure quaternion math seems unlikely to be a viable solution.</p>
  
  <p>However it might be nice to have a definitive answer to this here. Does anyone know any way to "fake" a position component of a quaternion, that in some way that would keep the quaternion math efficiency, or some other method to "accumulate" rotations around different origin points that is more efficient than just computing the matrix of the quaternions, and doing matrix translation and rotation multiplications for each and every quaternion? Or perhaps some mathematical assurance that differing pivot points don't actually make any difference, and can, in fact be applied later (but I doubt it).</p>
  
  <p>Or is using quaternions in this situation just a bad idea on the face of it?</p>