[37] | 1 | function P = change_basis(Q, B); |
---|
| 2 | % CHANGE_BASIS changes the basis of the quaternion Q, to the basis B. |
---|
| 3 | % Q may be a vector or matrix of quaternions, or a scalar quaternion. |
---|
| 4 | |
---|
| 5 | % Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
| 6 | % See the file : Copyright.m for further details. |
---|
| 7 | |
---|
| 8 | error(nargchk(2, 2, nargin)), error(nargoutchk(0, 1, nargout)) |
---|
| 9 | |
---|
| 10 | if ~isa(Q, 'quaternion') |
---|
| 11 | error('Q must be a quaternion, or a vector or matrix of quaternions.') |
---|
| 12 | end |
---|
| 13 | |
---|
| 14 | % Verify that B is an orthonormal basis. |
---|
| 15 | |
---|
| 16 | if size(B) ~= [3, 3] |
---|
| 17 | error('The basis, B, must be a 3 by 3 matrix.'); |
---|
| 18 | end |
---|
| 19 | |
---|
| 20 | if max(max(B * B.' - eye(3))) > 10 .* eps |
---|
| 21 | warning('The basis matrix is not accurately orthogonal.'); |
---|
| 22 | end |
---|
| 23 | |
---|
| 24 | % Construct three pure quaternions from B. |
---|
| 25 | |
---|
| 26 | V1 = quaternion(B(1,1), B(1,2), B(1,3)); |
---|
| 27 | V2 = quaternion(B(2,1), B(2,2), B(2,3)); |
---|
| 28 | V3 = quaternion(B(3,1), B(3,2), B(3,3)); |
---|
| 29 | |
---|
| 30 | % Change the basis of Q. This is done by resolving the vector part of Q |
---|
| 31 | % into the directions of the three basis vectors V1, V2 and V3. |
---|
| 32 | |
---|
| 33 | if ispure(Q) |
---|
| 34 | P = quaternion( dot(Q, V1), dot(Q, V2), dot(Q, V3)); |
---|
| 35 | else |
---|
| 36 | P = quaternion(s(Q), dot(Q, V1), dot(Q, V2), dot(Q, V3)); |
---|
| 37 | end |
---|