home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / quaternion / qmult.m < prev    next >
Text File  |  1998-10-23  |  575b  |  22 lines

  1. function retval = qmult(a,b)
  2.   # function retval = qmult(a,b)
  3.   # multiply two quaternions 
  4.   #  [w,x,y,z] = w*i + x*j + y*k + z
  5.   #  identities:
  6.   #    i^2 = j^2 = k^2 = -1
  7.   #    ij = k                    jk = i
  8.   #    ki = j                    kj = -i
  9.   #    ji = -k                   ik = -j
  10.   
  11.   [a1,b1,c1,d1] = quaternion(a);
  12.   [a2,b2,c2,d2] = quaternion(b);
  13.   
  14.   ri = b1*c2 - c1*b2 + d1*a2 + a1*d2;
  15.   rj = c1*a2 - a1*c2 + d1*b2 + b1*d2;
  16.   rk = a1*b2 - b1*a2 + d1*c2 + c1*d2;
  17.   rr = -(a1*a2 + b1*b2 + c1*c2) + d1*d2;
  18.   
  19.   retval = quaternion(ri,rj,rk,rr);
  20. endfunction
  21.  
  22.