home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FAQSYS18.ZIP / FAQS.DAT / QUATERNI.TXT < prev    next >
Text File  |  1996-07-31  |  4KB  |  129 lines

  1. ---------------------------------------------------------------------------
  2.  
  3. Quaternion Numbers
  4.  
  5. ---------------------------------------------------------------------------
  6.  
  7. Definition
  8.  
  9. A Quaternion number is an extension to complex numbers invented by Lord
  10. William Hamilton. A Quaternion number has got two extra imaginary units
  11. which are called j and k. We write such a number as q = a + b*i + c*j +
  12. d*k, or for short: (a, b, c, d). As long as c and d are equal to zero, q is
  13. nothing else then a complex number. These are the multiplication rules for
  14. i, j, k:
  15.  
  16.    i*i = j*j = k*k = -1
  17.    i*j = k,    j*i = -k
  18.    j*k = i,    k*j = -i
  19.    k*i = j,    i*k = -j
  20.  
  21. One can see these rules as if i, j, k are three orthognal unit vectors, the
  22. multiplication acts like a right-handed cross product of them. These rules
  23. does not cause any real difficulty until we look at multiplication of
  24. quaternions. Later on this page we see a very important fact:
  25. multiplication/division of quaternions is not commutative.
  26.  
  27. Conjugate, Norm and Absolute value
  28.  
  29.    q = (a, b, c, d)
  30.  
  31.    conj(q) = (a, -b, -c, -d)
  32.    norm(q) = a*a + b*b + c*c + d*d
  33.    abs(q)  = sqrt(norm(q))
  34.  
  35. Addition and subtraction
  36.  
  37.    q = (a, b, c, d), p = (x, y, z, w)
  38.  
  39.    q + p = (a+x, b+y, c+z, d+w)
  40.    q - p = (a-x, b-y, c-z, d-w)
  41.  
  42. Scaling
  43.  
  44.    q = (a, b, c, d)
  45.    t = Real value
  46.  
  47.    t*q = q*t = (t*a, t*b, t*c, t*d)
  48.  
  49. Multiplication
  50.  
  51.    q = (a, b, c, d), p = (x, y, z, w)
  52.  
  53.    q * p = (a + b*i + c*j + d*k) * (x + y*i + z*j + w*k)
  54.  
  55.          =   a   * (x + y*i + z*j + w*k)
  56.            + b*i * (x + y*i + z*j + w*k)
  57.            + c*j * (x + y*i + z*j + w*k)
  58.            + d*k * (x + y*i + z*j + w*k)
  59.  
  60.          =   a*x   + a*y*i + a*z*j + a*w*k
  61.            + b*x*i - b*y   + b*z*k - b*w*j
  62.            + c*x*j - c*y*k - c*z   + c*w*i
  63.            + d*x*k + d*y*j - d*z*i - d*w
  64.  
  65.          = (a*x - b*y - c*z - d*w,
  66.             a*y + b*x + c*w - d*z,
  67.             a*z - b*w + c*x + d*y,
  68.             a*w + b*z - c*y + d*x)
  69.  
  70. One can rewrite this if we define two 3-dimensional vectors:
  71.  
  72.    qV = (b, c, d)      q = (a, qV)
  73.    pV = (y, z, w)      p = (x, pV)
  74.  
  75.    q * p = (a*x - dotprod(qV, pV),
  76.             a*pV + x*qV + crossprod(qV, pV))
  77.  
  78. Now it is easy to see that multiplication of quaternion is not commutative,
  79. since the cross product of the vectors is not commutative. One must take
  80. this in consideration while working with quaternion algebra.
  81.  
  82. If we square a quaternion, the cross product is zero:
  83.  
  84.    q * q = (a*a - dotprod(qV, qV), 2*a*qV)
  85.  
  86. In fact, One do not have to consider the multiplication order at all when
  87. raising a quaternion to any positive integer power.
  88.  
  89. Fast multiplication
  90.  
  91. There are some schemes available that reduces the number of internal
  92. multiplications when doing quaternion multiplication. Here is one:
  93.  
  94.    q = (a, b, c, d), p = (x, y, z, w)
  95.  
  96.    tmp_00 = (d - c) * (z - w)
  97.    tmp_01 = (a + b) * (x + y)
  98.    tmp_02 = (a - b) * (z + w)
  99.    tmp_03 = (c + d) * (x - y)
  100.    tmp_04 = (d - b) * (y - z)
  101.    tmp_05 = (d + b) * (y + z)
  102.    tmp_06 = (a + c) * (x - w)
  103.    tmp_07 = (a - c) * (x + w)
  104.    tmp_08 = tmp_05 + tmp_06 + tmp_07
  105.    tmp_09 = 0.5 * (tmp_04 + tmp_08)
  106.  
  107.    q * p = (tmp_00 + tmp_09 - tmp_05,
  108.             tmp_01 + tmp_09 - tmp_08,
  109.             tmp_02 + tmp_09 - tmp_07,
  110.             tmp_03 + tmp_09 - tmp_06)
  111.  
  112. With this method You get 7 less multiplications, but 15 more
  113. additions/subtractions. Generally, this is still an improvement.
  114.  
  115. Inverse and division
  116.  
  117.    inv(q) = conj(q)/norm(q)
  118.  
  119.    q / p = inv(p)*q  or  q*inv(p)
  120.  
  121. Here it can be difficult to know which one to choose. I do not use division
  122. very often, but when I have to I always use q/p = +inv(p)*q. If I use it
  123. all the time, there seems to be no problem. I am not that good at
  124. explaining this, if someone knows better please send me an email.
  125. ---------------------------------------------------------------------------
  126. [Image]  [Image]
  127.  
  128. Last update by Henrik Engstr÷m 1994-Oct-27
  129.