1 | function q = isoquaternion(z, a) |
---|
2 | % Construct a quaternion from a complex number, preserving the modulus and |
---|
3 | % argument, and using the axis of the second argument as the axis of the |
---|
4 | % result. |
---|
5 | |
---|
6 | % Copyright © 2006 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') |
---|
12 | error('Second argument must be a quaternion.') |
---|
13 | end; |
---|
14 | |
---|
15 | if isa(z,'quaternion') |
---|
16 | error('First argument must not be a quaternion.') |
---|
17 | end; |
---|
18 | |
---|
19 | if isreal(z) |
---|
20 | % The imaginary part of z is zero, therefore so must be the vector part |
---|
21 | % of the result. We use special code for this case to avoid calling the |
---|
22 | % axis function, because axis(a) is almost certainly undefined. |
---|
23 | |
---|
24 | q = quaternion(real(z), 0, 0, 0); |
---|
25 | else |
---|
26 | q = quaternion(real(z), imag(z) .* axis(a)); |
---|
27 | end; |
---|
28 | |
---|
29 | % Note: the complex argument z may be in any of the four quadrants of the |
---|
30 | % plane, and so may the quaternion result. This means that if the axis is |
---|
31 | % extracted from the quaternion result, it may point in the opposite |
---|
32 | % direction to the axis of the second argument, a. |
---|