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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
3452
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
3452
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} qmult (@var{a}, @var{b}) |
|
21 ## Multiply two quaternions. |
|
22 ## |
|
23 ## @example |
|
24 ## [w, x, y, z] = w*i + x*j + y*k + z |
|
25 ## @end example |
|
26 ## |
|
27 ## @noindent |
|
28 ## identities: |
|
29 ## |
|
30 ## @example |
|
31 ## i^2 = j^2 = k^2 = -1 |
|
32 ## ij = k jk = i |
|
33 ## ki = j kj = -i |
|
34 ## ji = -k ik = -j |
|
35 ## @end example |
|
36 ## @end deftypefn |
|
37 |
|
38 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
39 ## Adapted-By: jwe |
|
40 |
|
41 function retval = qmult (a, b) |
3224
|
42 |
3452
|
43 [a1, b1, c1, d1] = quaternion (a); |
|
44 [a2, b2, c2, d2] = quaternion (b); |
3224
|
45 |
|
46 ri = b1*c2 - c1*b2 + d1*a2 + a1*d2; |
|
47 rj = c1*a2 - a1*c2 + d1*b2 + b1*d2; |
|
48 rk = a1*b2 - b1*a2 + d1*c2 + c1*d2; |
|
49 rr = -(a1*a2 + b1*b2 + c1*c2) + d1*d2; |
|
50 |
3452
|
51 retval = quaternion (ri, rj, rk, rr); |
|
52 |
3224
|
53 endfunction |
|
54 |