3452
|
1 ## Copyright (C) 1998 Auburn University. All rights reserved. |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
3224
|
19 |
3452
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} qtransv (@var{v}, @var{q}) |
|
22 ## Transform the 3-D vector @var{v} by the unit quaternion @var{q}. |
|
23 ## Return a column vector. |
|
24 ## |
|
25 ## @example |
|
26 ## vi = (2*real(q)^2 - 1)*vb + 2*imag(q)*(imag(q)'*vb) |
|
27 ## + 2*real(q)*cross(imag(q),vb) |
|
28 ## @end example |
|
29 ## |
|
30 ## @noindent |
|
31 ## Where imag(q) is a column vector of length 3. |
|
32 ## @end deftypefn |
3224
|
33 |
3452
|
34 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
35 ## Adapted-By: jwe |
|
36 |
|
37 function vi = qtransv (vb, qib) |
|
38 |
4030
|
39 if (! isvector (vb) || length (vb) != 3) |
3452
|
40 error ("qtransv: v(%d,%d) must be a 3-D vector", rows (vb), columns (vb)); |
4030
|
41 elseif (! isvector (qib) || length (qib) != 4) |
3452
|
42 error ("qtransv: q(%d,%d) must be a quaternion", rows (qib), columns (qib)); |
|
43 elseif (max (abs (imag (vb))) + max (abs (imag (qib))) != 0) |
3458
|
44 error ("qtransv: input values must be real"); |
3452
|
45 endif |
|
46 |
|
47 qr = qib(4); |
|
48 qimag = vec (qib(1:3)); |
|
49 vb = vec (vb); |
|
50 vi = (2*qr^2 - 1)*vb + 2*qimag*(qimag'*vb) + 2*qr*cross (qimag, vb); |
3224
|
51 |
|
52 endfunction |