forked from dplab/MechMet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRMatOfBunge.m
62 lines (62 loc) · 1.47 KB
/
RMatOfBunge.m
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function rmat = RMatOfBunge(bunge, units)
% RMatOfBunge - Rotation matrix from Bunge angles.
%
% USAGE:
%
% rmat = RMatOfBunge(bunge, units)
%
% INPUT:
%
% bunge is 3 x n,
% the array of Bunge parameters
% units is a string,
% either 'degrees' or 'radians'
%
% OUTPUT:
%
% rmat is 3 x 3 x n,
% the corresponding rotation matrices
%
if (nargin < 2)
error('need second argument, units: ''degrees'' or ''radians''')
end
%
if (strcmp(units, 'degrees'))
%
indeg = 1;
bunge = bunge*(pi/180);
%
elseif (strcmp(units, 'radians'))
indeg = 0;
else
error('angle units need to be specified: ''degrees'' or ''radians''')
end
%
n = size(bunge, 2);
cbun = cos(bunge);
sbun = sin(bunge);
%
rmat = [
cbun(1, :).*cbun(3, :) - sbun(1, :).*cbun(2, :).*sbun(3, :);
sbun(1, :).*cbun(3, :) + cbun(1, :).*cbun(2, :).*sbun(3, :);
sbun(2, :).*sbun(3, :);
-cbun(1, :).*sbun(3, :) - sbun(1, :).*cbun(2, :).*cbun(3, :);
-sbun(1, :).*sbun(3, :) + cbun(1, :).*cbun(2, :).*cbun(3, :);
sbun(2, :).*cbun(3, :);
sbun(1, :).*sbun(2, :);
-cbun(1, :).*sbun(2, :);
cbun(2, :)
];
rmat = reshape(rmat, [3 3 n]);
%
% From MPS: pxutils.f
%
% mat(1, 1) = c1*c3 - s1*c2*s3
% mat(2, 1) = s1*c3 + c1*c2*s3
% mat(3, 1) = s2*s3
% mat(1, 2) = -c1*s3 - s1*c2*c3
% mat(2, 2) = -s1*s3 + c1*c2*c3
% mat(3, 2) = s2*c3
% mat(1, 3) = s1*s2
% mat(2, 3) = -c1*s2
% mat(3, 3) = c2