source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/qtfm/@quaternion/mtimes.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 1.6 KB
Line 
1function q = mtimes(l, r)
2% *   Matrix multiply.
3% (Quaternion overloading of standard Matlab function.)
4 
5% Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan.
6% See the file : Copyright.m for further details.
7
8error(nargchk(2, 2, nargin)), error(nargoutchk(0, 1, nargout))
9
10if isa(l, 'quaternion') & isa(r, 'quaternion')
11   
12    % Both arguments are quaternions. There are four cases to handle,
13    % dependent on whether the arguments are pure or full.
14   
15    if ispure(l) & ispure(r)
16        q = -mdot(l, r) + mcross(l, r);
17    elseif ispure(l)
18        q =                 l  * s(r) +             +   l  * v(r);
19    elseif ispure(r)
20        q =                             s(l) *   r  + v(l) *   r;
21    else
22        q = s(l) * s(r) + v(l) * s(r) + s(l) * v(r) + v(l) * v(r);
23    end
24   
25else
26    % One of the arguments is not a quaternion. If it is numeric, we can handle it,
27    % and we must because the code above requires us to multiply scalar parts by
28    % vector parts using a recursive call to this function.
29   
30    if isa(l, 'quaternion') & isa(r, 'numeric')
31        if ispure(l)
32            q = quaternion(           x(l) * r, y(l) * r, z(l) * r);
33        else
34            q = quaternion(s(l) * r, x(l) * r, y(l) * r, z(l) * r);
35        end
36    elseif isa(l, 'numeric') & isa(r, 'quaternion')
37        if ispure(r)
38            q = quaternion(           l * x(r), l * y(r), l * z(r));
39        else
40            q = quaternion(l * s(r), l * x(r), l * y(r), l * z(r));
41        end
42    else
43        error('Matrix multiplication of a quaternion by a non-numeric is not implemented.')
44    end
45end
46
47
48
Note: See TracBrowser for help on using the repository browser.