1 | function B = orthonormal_basis(V, W); |
---|
2 | % ORTHONORMAL_BASIS creates an orthonormal basis from a pure quaternion V, |
---|
3 | % and an optional pure quaternion W, which need not be perpendicular to V, |
---|
4 | % but must not be parallel. |
---|
5 | % |
---|
6 | % The result is represented as a 3 by 3 orthogonal matrix, which may be |
---|
7 | % complex if V and/or W are complex pure quaternions. |
---|
8 | |
---|
9 | % Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
10 | % See the file : Copyright.m for further details. |
---|
11 | |
---|
12 | error(nargchk(1, 2, nargin)), error(nargoutchk(0, 1, nargout)) |
---|
13 | |
---|
14 | if size(V) ~= [1, 1] |
---|
15 | error('V must not be a vector or matrix.'); |
---|
16 | end |
---|
17 | |
---|
18 | if ~isa(V, 'quaternion') | ~ispure(V) |
---|
19 | error('V must be a pure quaternion.') |
---|
20 | end |
---|
21 | |
---|
22 | V = unit(V); % Ensure that V is a unit pure quaternion. |
---|
23 | |
---|
24 | if nargin == 1 |
---|
25 | W = orthogonal(V); |
---|
26 | else |
---|
27 | W = orthogonal(V, W); |
---|
28 | end |
---|
29 | |
---|
30 | X = orthogonal(V, W); |
---|
31 | |
---|
32 | B = [x(V), y(V), z(V); x(W), y(W), z(W); x(X), y(X), z(X)]; |
---|
33 | |
---|
34 | % It is possible for the result to be inaccurate, and therefore we check |
---|
35 | % that B is sufficiently orthogonal before returning. Error is particularly |
---|
36 | % likely in the complex case if V and/or W is not defined accurately. |
---|
37 | % (See the discussion note in the function unit.m.) |
---|
38 | |
---|
39 | if norm(B * B.' - eye(3)) > 5.*eps |
---|
40 | warning('The basis matrix is not accurately orthogonal.'); |
---|
41 | end |
---|