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

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

Added original make3d

File size: 1.1 KB
Line 
1function 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
8error(nargchk(2, 2, nargin)), error(nargoutchk(0, 1, nargout))
9
10if ~isa(Q, 'quaternion')
11    error('Q must be a quaternion, or a vector or matrix of quaternions.')
12end
13
14% Verify that B is an orthonormal basis.
15
16if size(B) ~= [3, 3]
17    error('The basis, B, must be a 3 by 3 matrix.');
18end
19
20if max(max(B * B.' - eye(3))) > 10 .* eps
21    warning('The basis matrix is not accurately orthogonal.');
22end
23
24% Construct three pure quaternions from B.
25
26V1 = quaternion(B(1,1), B(1,2), B(1,3));
27V2 = quaternion(B(2,1), B(2,2), B(2,3));
28V3 = 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
33if ispure(Q)
34    P = quaternion(      dot(Q, V1), dot(Q, V2), dot(Q, V3));
35else
36    P = quaternion(s(Q), dot(Q, V1), dot(Q, V2), dot(Q, V3));
37end
Note: See TracBrowser for help on using the repository browser.