home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / quaternion / qtransv.m < prev    next >
Text File  |  1998-12-04  |  833b  |  24 lines

  1. function vi = qtransv(vb,qib)
  2. # function vi = qtransv(vb,q)
  3. # transform the 3-D vector v by the unit quaternion q;
  4. # v = [w x y z], q = transformation quaternion
  5. # returns vi = column vector
  6. #    vi = (2*real(q)^2 - 1)*vb + 2*imag(q)*(imag(q)'*vb) 
  7. #      + 2*real(q)*cross(imag(q),vb)
  8. #    where imag(q) is a column vector of length 3.
  9.  
  10. if(!is_vector(vb) | length(vb) != 3)
  11.   error(sprintf("qtransv: v(%d,%d) must be a 3-D vector",rows(vb),columns(vb)))
  12. elseif(!is_vector(qib) | length(qib) != 4)
  13.   error(sprintf("qtransv: q(%d,%d) must be a quaternion",rows(qib),columns(qib)))
  14. elseif(max(abs(imag(vb))) + max(abs(imag(qib))) != 0)
  15.   vb
  16.   qib
  17.   error("qtransv: input values must be real.");
  18. endif
  19.  
  20. qr = qib(4);  qimag = vec(qib(1:3));   vb = vec(vb);
  21. vi = (2*qr^2 - 1)*vb + 2*qimag*(qimag'*vb) + 2*qr*cross(qimag,vb);
  22.  
  23. endfunction
  24.