Get spherical coordinates for a point in Cartesian coordinates - Parameters: structure stPt with fields x,y,z (possibly arrays) - Returns: structure stPtSph with fields r, theta, phi (same size as x,y,z) This file is part of the SPlaC v1.0 package (copyright 2008) Check the README file for further information
0001 stPtSph.r=sqrt( (stPt.x).^2 + (stPt.y).^2 + (stPt.z).^2);
0002 % use atan2 to avoid infinities problems
0003 stPtSph.theta=pi/2-atan2(stPt.z,sqrt((stPt.x).^2+(stPt.y).^2));
0004 stPtSph.phi=atan2(stPt.y,stPt.x);
0005