September 29, 2013

Quaternion as 3D Rotation Hand

Quaternion algebra was introduced by Hamilton in 1843. It is powerful three dimensional complex number system. This article will present how to use quaternion  as rotation tools which is very useful for the calculation involving three-dimensional rotation in 3D computer graphics.

In order to match with OpenGL, this article apply the right hand rule to explain quaternion . If you come across another article which based on the left hand rule , do not be surprised to see that the terms are different to those described in this article.


Quaternion multiplication of basis element

  Q  =  w  +  x i   +   yj   +  zk  

   where  i , j , k  is complex number   w,x,y,z  are real number

     i2  =    j2  =   k2  =   i j k   =   -1

    ij = k  ;   ji = -k

    jk = i  ;   kj = -i

    ki =j   ;  ik = -j

   The  x,y,z  is rotation axis  and   w  is some thing which relate to the rotation angle required.

Quaternion Product

      define qutaternion   Q1  and Q2

      Q1  =  w1  +  x1 i   +   y1 j   +  z1 k     =   w1 +  v1     where  v1  = (  x1 i   +   y1 j   +  z1 k  )

      Q2  =  w2 +  x2 i    +   y2 j   +  z2 k     =   w2 +  v2     weher  v2  =  ( x2 i   +   y2 j   +  z2 k )

      Q1*Q2  =  w1w2 +  w1v2 +w2v1 + v1v2

      v1v2    =    - ( x1x2 + y1y2 +z1z2 ),     ==>   -  ( v1.v2 )  dot product
                   
                        + (y1z2  - z1y2)  i ,
                        + (z1x2  - x1z2)  j ,             ==>       ( v1 x v2 )      cross product
                        + (x1y2  - y1x2)  k

       Q1*Q2    =   w1w2 + w1v2 +w2v1 - v1.v2 + v1 x v2
                      = ( w1w2  - v1.v2)    +  (w1v2 +w2v1  + v1 x v2)
                      = ........
 
                   replace the terms with

                   i2 =   j2 =  k2 =   i j k   =   -1
 
                   ij = k  ;   ji = -k
 
                   jk = i  ;   kj = -i
 
                   ki =j   ;  ik = -j