7017
|
1 ## Copyright (C) 1998, 2000, 2005, 2007 |
|
2 ## Auburn University. All rights reserved. |
3452
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
7016
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3452
|
10 ## |
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
3452
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} qmult (@var{a}, @var{b}) |
|
22 ## Multiply two quaternions. |
|
23 ## |
|
24 ## @example |
|
25 ## [w, x, y, z] = w*i + x*j + y*k + z |
|
26 ## @end example |
|
27 ## |
|
28 ## @noindent |
|
29 ## identities: |
|
30 ## |
|
31 ## @example |
|
32 ## i^2 = j^2 = k^2 = -1 |
|
33 ## ij = k jk = i |
|
34 ## ki = j kj = -i |
|
35 ## ji = -k ik = -j |
|
36 ## @end example |
|
37 ## @end deftypefn |
|
38 |
|
39 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
40 ## Adapted-By: jwe |
|
41 |
|
42 function retval = qmult (a, b) |
7125
|
43 |
|
44 if (nargin != 2 ) |
|
45 print_usage (); |
|
46 endif |
|
47 |
3452
|
48 [a1, b1, c1, d1] = quaternion (a); |
|
49 [a2, b2, c2, d2] = quaternion (b); |
3224
|
50 |
|
51 ri = b1*c2 - c1*b2 + d1*a2 + a1*d2; |
|
52 rj = c1*a2 - a1*c2 + d1*b2 + b1*d2; |
|
53 rk = a1*b2 - b1*a2 + d1*c2 + c1*d2; |
|
54 rr = -(a1*a2 + b1*b2 + c1*c2) + d1*d2; |
|
55 |
3452
|
56 retval = quaternion (ri, rj, rk, rr); |
|
57 |
3224
|
58 endfunction |
|
59 |