elec_cart2sph.m

来自「Matlab下的EEG处理程序库」· M 代码 · 共 39 行

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

% 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);
%

% $Revision: 1.2 $ $Date: 2003/03/02 03:20:44 $

% Licence:  GNU GPL, no implied or express warranties
% History:  07/2001, Darren.Weber@flinders.edu.au
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if ~exist('xo', 'var') xo = 0; end
if ~exist('yo', 'var') yo = 0; end
if ~exist('zo', 'var') zo = 0; end

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 );

return

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?