Home > bioelectromagnetism > Rz.m

Rz

PURPOSE ^

rz - Rotate 3D Cartesian coordinates around the Z axis

SYNOPSIS ^

function [XYZ] = rz(XYZ,g,units)

DESCRIPTION ^

 rz - Rotate 3D Cartesian coordinates around the Z axis

 Useage: [XYZ] = rz(XYZ,gamma,units)

 XYZ is a [3,N] or [N,3] matrix of 3D Cartesian coordinates

 'gamma' - angle of rotation about the Z axis
 'units' - angle is either 'degrees' or 'radians'
           the default is gamma in radians
 
 If input XYZ = eye(3), the XYZ returned is
 the rotation matrix.
 
 See also rx ry

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [XYZ] = rz(XYZ,g,units)
0002 
0003 % rz - Rotate 3D Cartesian coordinates around the Z axis
0004 %
0005 % Useage: [XYZ] = rz(XYZ,gamma,units)
0006 %
0007 % XYZ is a [3,N] or [N,3] matrix of 3D Cartesian coordinates
0008 %
0009 % 'gamma' - angle of rotation about the Z axis
0010 % 'units' - angle is either 'degrees' or 'radians'
0011 %           the default is gamma in radians
0012 %
0013 % If input XYZ = eye(3), the XYZ returned is
0014 % the rotation matrix.
0015 %
0016 % See also rx ry
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     g = g*pi/180;
0033 end
0034 
0035 Rz = [ cos(g) -sin(g) 0;  sin(g) cos(g) 0;  0 0 1 ];
0036 
0037 if isequal(size(XYZ,1),3),
0038     XYZ = Rz * XYZ;
0039 else
0040     XYZ = XYZ';
0041     if isequal(size(XYZ,1),3),
0042         XYZ = [Rz * XYZ]';
0043     else
0044         error('Rz: 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