Skip to content
Snippets Groups Projects
Commit 86744eeb authored by Peter Reischig's avatar Peter Reischig Committed by Nicola Vigano
Browse files

Added 'row'/'col' input to gtMathsRotationMatrixComp to avoid confusion....

Added 'row'/'col' input to gtMathsRotationMatrixComp to avoid confusion. Modified the caller functions accordingly.

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@543 4c865b51-4357-4376-afb4-474e03ccb993
parent 097fc3e2
No related branches found
No related tags found
No related merge requests found
function rotmatcomp = gtMathsRotationMatrixComp(rotdir)
function rotmatcomp = gtMathsRotationMatrixComp(rotdir, rc)
% GTMATHSROTATIONMATRIXCOMP
% rotmatcomp = gtMathsRotationMatrixComp(rotdir)
% rotmatcomp = gtMathsRotationMatrixComp(rotdir, rc)
% ----------------------------------------------
%
% Given an arbitrary rotation axis in 3D space, returns the three matrices
% in Rodrigues's formula. The matrices can be used to compose the rotation
% tensor. Considers right-handed rotation for a positive angle.
% Given an arbitrary rotation axis in 3D space, returns the three
% matrices in Rodrigues's formula (see below). The matrices can be
% used to compose the rotation matrix for any angle. It considers
% right-handed rotation for a positive angle.
%
% To be used with ROW VECTORS, MULTIPLY FROM THE RIGHT side!
% Multiplication of column vectors from the left gives the wrong result!
% Output to be used with row or column vectors:
% 1. For ROW VECTORS: rowvector_rotated = rowvector*Srot
% 2. For COLUMN VECTORS: colvector_rotated = Srot*colvector
% NOTE: Using the matrix on the wrong side gives the inverse result!
%
% Rodrigues's rotation formula describes a linear combination of
% Rodrigues's rotation formula describes a linear combination of three
% matrices with only cos(om) and only sin(om) dependent terms:
% Srot = Sconst + Scos*cos(om) + Ssin*sin(om)
% Srot: rotation tensor for a row vector:
% rowvector_rotated = rowvector*Srot
% Srot: 3x3 rotation matrix
% for row vectors: rowvector_rotated = rowvector*Srot
% for column vectors: colvector_rotated = Srot*colvector
% om : rotation angle
%
% To get Srot from the components, use gtMathsRotationTensor.
%
%
% INPUT
% rotdir - rotation axis direction in LAB coordinates for right-handed
% rotation; unit vector (1,3)
% rotation; unit vector (1x3 for row, 3x1 for column vectors)
% rc - 'row' for row vectors, 'col' for column vectors
%
% OUTPUT
% rotmatcomp.const = matrix Sconst (3,3)
% rotmatcomp.cos = matrix Scos (3,3)
% rotmatcomp.sin = matrix Ssin (3,3)
% rotmatcomp.const = matrix Sconst (3x3)
% rotmatcomp.cos = matrix Scos (3x3)
% rotmatcomp.sin = matrix Ssin (3x3)
if ((size(rotdir,1) ~= 1) || (size(rotdir,2) ~= 3))
error('Input rotdir has to be a 1x3 row vector.')
end
if strcmp(rc,'row') && (size(rotdir,1) == 1) && (size(rotdir,2) == 3)
rotmatcomp.const = rotdir' * rotdir;
rotmatcomp.cos = eye(3) - rotmatcomp.const;
rotmatcomp.sin = [ 0, rotdir(3), -rotdir(2) ; ...
-rotdir(3), 0, rotdir(1) ; ...
rotdir(2), -rotdir(1), 0 ];
elseif strcmp(rc,'col') && (size(rotdir,1) == 3) && (size(rotdir,2) == 1)
rotmatcomp.const = rotdir * rotdir';
rotmatcomp.cos = eye(3) - rotmatcomp.const;
rotmatcomp.sin = [ 0, -rotdir(3), rotdir(2) ; ...
rotdir(3), 0, -rotdir(1) ; ...
-rotdir(2), rotdir(1), 0 ];
else
error('Wrong input format. See function help.')
end
end % end of function
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment