[d164bf]: / tool_funcs / computeXYZAngleSeq.m

Download this file

34 lines (31 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
% COMPUTEXYZANGLESEQ Convert a rotation matrix in the orientation vector
% used in OpenSim (X-Y-Z axes rotation order).
%
% orientation = computeXYZAngleSeq(aRotMat)
%
% Inputs:
% aRotMat - a rotation matrix, normally obtained writing as columns the
% axes of the body reference system, expressed in global reference
% system.
%
% Outputs:
% orientation - the sequence of angles used in OpenSim to define the
% joint orientation. Sequence of rotation is X-Y-Z.
%
%-------------------------------------------------------------------------%
% Author: Luca Modenese, 2021
% Copyright 2021 Luca Modenese
%-------------------------------------------------------------------------%
%
% FUNCTION FROM msk-STAPLE toolbox.
%
%-------------------------------------------------------------------------%
function orientation = computeXYZAngleSeq(aRotMat)
% fixed body sequence of angles from rot mat usable for orientation in
% OpenSim
beta = atan2(aRotMat(1,3), sqrt(aRotMat(1,1)^2.0+aRotMat(1,2)^2.0));
alpha = atan2(-aRotMat(2,3)/cos(beta), aRotMat(3,3)/cos(beta));
gamma = atan2(-aRotMat(1, 2)/cos(beta), aRotMat(1,1)/cos(beta));
% build a vector
orientation = [ alpha beta gamma];
end