Home > bioelectromagnetism > Rx.m

Rx

PURPOSE ^

rx - Rotate 3D Cartesian coordinates around the X axis

SYNOPSIS ^

function [XYZ] = rx(XYZ,a,units)

DESCRIPTION ^

 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [XYZ] = rx(XYZ,a,units)
0002 
0003 % rx - Rotate 3D Cartesian coordinates around the X axis
0004 %
0005 % Useage: [XYZ] = rx(XYZ,alpha,units)
0006 %
0007 % XYZ is a [3,N] or [N,3] matrix of 3D Cartesian coordinates
0008 %
0009 % 'alpha' - angle of rotation about the X axis
0010 % 'units' - angle is either 'degrees' or 'radians'
0011 %           the default is alpha in radians
0012 %
0013 % If input XYZ = eye(3), the XYZ returned is
0014 % the rotation matrix.
0015 %
0016 % See also ry rz
0017 %
0018 
0019 % $Revision: 1.1 $ $Date: 2004/11/12 01:30:25 $
0020 
0021 % Licence:  GNU GPL, no express or implied warranties
0022 % History:  04/2002, Darren.Weber_at_radiology.ucsf.edu
0023 %                    Developed after example 3.1 of
0024 %                    Mathews & Fink (1999), Numerical
0025 %                    Methods Using Matlab. Prentice Hall: NY.
0026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0027 
0028 if ~exist('units','var'), units = 'radians'; end
0029 
0030 % convert degrees to radians
0031 if isequal(units,'degrees'),
0032     a = a*pi/180;
0033 end
0034 
0035 Rx = [1 0 0; 0 cos(a) -sin(a); 0 sin(a) cos(a) ];
0036 
0037 if isequal(size(XYZ,1),3),
0038     XYZ = Rx * XYZ;
0039 else
0040     XYZ = XYZ';
0041     if isequal(size(XYZ,1),3),
0042         XYZ = [Rx * XYZ]';
0043     else
0044         error('Rx: Input XYZ must be [N,3] or [3,N] matrix.\n');
0045     end
0046 end
0047 
0048 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003