-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rx.m
48 lines (40 loc) · 1.2 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
function [XYZ] = rx(XYZ,a,units)
% rx - Rotate 3D Cartesian coordinates around the X axis
%
% Useage: [XYZ] = rx(XYZ,alpha,units)
%
% XYZ is a [3,N] or [N,3] matrix of 3D Cartesian coordinates
%
% 'alpha' - angle of rotation about the X axis
% 'units' - angle is either 'degrees' or 'radians'
% the default is alpha in radians
%
% If input XYZ = eye(3), the XYZ returned is
% the rotation matrix.
%
% See also ry rz
%
% $Revision: 1.1 $ $Date: 2004/11/12 01:30:25 $
% Licence: GNU GPL, no express or implied warranties
% History: 04/2002, Darren.Weber_at_radiology.ucsf.edu
% Developed after example 3.1 of
% Mathews & Fink (1999), Numerical
% Methods Using Matlab. Prentice Hall: NY.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ~exist('units','var'), units = 'radians'; end
% convert degrees to radians
if isequal(units,'degrees'),
a = a*pi/180;
end
Rx = [1 0 0; 0 cos(a) -sin(a); 0 sin(a) cos(a) ];
if isequal(size(XYZ,1),3),
XYZ = Rx * XYZ;
else
XYZ = XYZ';
if isequal(size(XYZ,1),3),
XYZ = [Rx * XYZ]';
else
error('Rx: Input XYZ must be [N,3] or [3,N] matrix.\n');
end
end
return