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 |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
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) |
3224
|
43 |
3452
|
44 [a1, b1, c1, d1] = quaternion (a); |
|
45 [a2, b2, c2, d2] = quaternion (b); |
3224
|
46 |
|
47 ri = b1*c2 - c1*b2 + d1*a2 + a1*d2; |
|
48 rj = c1*a2 - a1*c2 + d1*b2 + b1*d2; |
|
49 rk = a1*b2 - b1*a2 + d1*c2 + c1*d2; |
|
50 rr = -(a1*a2 + b1*b2 + c1*c2) + d1*d2; |
|
51 |
3452
|
52 retval = quaternion (ri, rj, rk, rr); |
|
53 |
3224
|
54 endfunction |
|
55 |