-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRx.m
52 lines (47 loc) · 1.27 KB
/
Rx.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
function R = Rx(theta)
% Rx
%
% Produces a direction cosine matrix (rotation) corresponding to a frame
% rotation about [1 0 0]'.
%
% Note that this is *frame* rotation and is the opposite of *vector*
% rotation.
%
% For example, suppose we're observing a vector in some frame, A, called
% vA. Now let's suppose that some frame, B, is rotated from A by theta
% about [1 0 0]'. Then the vector expressed in the rotated frame, B, is
% given by:
%
% vB = Rx(theta) * vA;
%
% Let's look at the opposite. Suppose some vector is v = [0 1 0]', and we
% want to rotate this vector (not the frame from which we view it) by pi/4.
% Since this is the opposite of frame rotation, we can achieve the rotated
% vector with either:
%
% vr = Rx(-pi/4) * [0 1 0]'
%
% or
%
% vr = Rx(pi/4)' * [0 1 0]'
%
% This usage corresponds with the general notation used in _Quaternions and
% Rotation Sequences_ by Jack B. Kuiper.
%
% See also: Ry, Rz, aa2dcm
% Copyright 2016 An Uncommon Lab
%#ok<*EMTAG>
%#eml
%#codegen
% c = cos(theta);
% s = sin(theta);
% R = [ 1 0 0; ...
% 0 c s; ...
% 0 -s c];
R = zeros(3, 3, length(theta), class(theta));
R(1,1,:) = 1;
R(2,2,:) = cos(theta);
R(3,3,:) = R(2,2,:);
R(2,3,:) = sin(theta);
R(3,2,:) = -R(2,3,:);
end % Rx