Home > bioelectromagnetism > elec_cart2sph.m

elec_cart2sph

PURPOSE ^

elec_cart2sph - Convert Cartesian (X,Y,Z) to spherical (theta,phi,r)

SYNOPSIS ^

function [theta,phi,r] = elec_cart2sph(x,y,z,xo,yo,zo)

DESCRIPTION ^

 elec_cart2sph - Convert Cartesian (X,Y,Z) to spherical (theta,phi,r)

 Useage: [theta,phi,r] = elec_cart2sph(X,Y,Z,xo,yo,zo)

 Result:   (theta,phi,r) are double floating point (Nx1);
           r is radius,
           theta is counterclockwise rotation from +x in x-y plane (azimuth),
           phi is elevation with respect to Cz-axis,
           theta & phi in radians,

           +ve x-axis from origin through T4 (right ear)
           +ve y-axis from origin through Nasion (at theta = +90degrees)
           
 Note:     Conversion from Cartesian to spherical coordinates, with
           origin or centroid (xo,yo,zo) is:
           theta = atan( (y-yo) ./ (x-xo) );
           phi = atan( sqrt( (x-xo).^2 + (y-yo).^2 ) ./ (z-zo) );
           r = sqrt( (x-xo).^2 + (y-yo).^2 + (z-zo).^2);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [theta,phi,r] = elec_cart2sph(x,y,z,xo,yo,zo)
0002 
0003 % elec_cart2sph - Convert Cartesian (X,Y,Z) to spherical (theta,phi,r)
0004 %
0005 % Useage: [theta,phi,r] = elec_cart2sph(X,Y,Z,xo,yo,zo)
0006 %
0007 % Result:   (theta,phi,r) are double floating point (Nx1);
0008 %           r is radius,
0009 %           theta is counterclockwise rotation from +x in x-y plane (azimuth),
0010 %           phi is elevation with respect to Cz-axis,
0011 %           theta & phi in radians,
0012 %
0013 %           +ve x-axis from origin through T4 (right ear)
0014 %           +ve y-axis from origin through Nasion (at theta = +90degrees)
0015 %
0016 % Note:     Conversion from Cartesian to spherical coordinates, with
0017 %           origin or centroid (xo,yo,zo) is:
0018 %           theta = atan( (y-yo) ./ (x-xo) );
0019 %           phi = atan( sqrt( (x-xo).^2 + (y-yo).^2 ) ./ (z-zo) );
0020 %           r = sqrt( (x-xo).^2 + (y-yo).^2 + (z-zo).^2);
0021 %
0022 
0023 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $
0024 
0025 % Licence:  GNU GPL, no implied or express warranties
0026 % History:  07/2001, Darren.Weber_at_radiology.ucsf.edu
0027 %
0028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0029 
0030 if ~exist('xo', 'var') xo = 0; end
0031 if ~exist('yo', 'var') yo = 0; end
0032 if ~exist('zo', 'var') zo = 0; end
0033 
0034 theta = atan( (y-yo) ./ (x-xo) );
0035 phi = atan( sqrt( (x-xo).^2 + (y-yo).^2 ) ./ (z-zo) );
0036 r = sqrt( (x-xo).^2 + (y-yo).^2 + (z-zo).^2 );
0037 
0038 return

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