Rev | Line | |
---|
[37] | 1 | function d = dot(a, b) |
---|
| 2 | % DOT Quaternion dot product. |
---|
| 3 | % The dot (scalar) product of two quaternions is the sum of the products of |
---|
| 4 | % the (s, x, y, z) components of the two quaternions. |
---|
| 5 | |
---|
| 6 | % Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
| 7 | % See the file : Copyright.m for further details. |
---|
| 8 | |
---|
| 9 | error(nargchk(2, 2, nargin)), error(nargoutchk(0, 1, nargout)) |
---|
| 10 | |
---|
| 11 | if ~isa(a, 'quaternion') | ~isa(b, 'quaternion') |
---|
| 12 | error('Dot product is not defined for a quaternion and a non-quaternion.') |
---|
| 13 | end |
---|
| 14 | |
---|
| 15 | % This function is defined for full and pure quaternions, and combinations |
---|
| 16 | % of full and pure, in which case we assume a zero scalar part for the pure |
---|
| 17 | % argument. |
---|
| 18 | |
---|
| 19 | if ispure(a) | ispure(b) |
---|
| 20 | % This covers the case where either or both are pure. We can ignore the |
---|
| 21 | % scalar part of the other, since it is implicitly multiplied by zero. |
---|
| 22 | |
---|
| 23 | d = x(a) .* x(b) + y(a) .* y(b) + z(a) .* z(b); |
---|
| 24 | else |
---|
| 25 | d = s(a) .* s(b) + x(a) .* x(b) + y(a) .* y(b) + z(a) .* z(b); |
---|
| 26 | end |
---|
Note: See
TracBrowser
for help on using the repository browser.