;+
; Contains the xyz_to_rtp function
;
; :Author:
; Baptiste Cecconi, Philippe Zarka
;
; :History:
; 2008/01/10: Created
;
; 2008/01/10: Last Edit
;-
;
;+
; xyz_to_rtp is a function that <behavior desc here>
;
; :Returns:
; [r,t,p] en radians
; r = rayon
; theta = colatitude (utiliser '/latitude' pour sortir celle-ci)
; phi = azimuth
;
; :Params:
; xyz: in, required, type=sometype
; coordonnees en Rj
;
; :Keywords:
; latitude: in, optional, type=sometype
; sortir latitude au lieu de colatitude
;-
FUNCTION XYZ_TO_RTP, xyz, latitude=latitude
x = float(reform(xyz(0,*)))
y = float(reform(xyz(1,*)))
z = float(reform(xyz(2,*)))
r = sqrt(x^2+y^2+z^2)
theta = r*0.
phi = r*0.
; si r > 0, on peut faire le calcul de theta et phi.
ww = where(r ne 0, cnt)
if cnt ne 0 then begin
theta(ww) = acos(z(ww)/r(ww))
; la latitude n'est pas +/- pi/2, on peut calculer phi
ww1 = where(abs(theta(ww)) ne !pi/2.,cnt1)
if cnt1 ne 0 then phi(ww(ww1)) =atan(y(ww(ww1)),x(ww(ww1)))
; dans le cas ou on veut la latitude, on modifie theta:
if keyword_set(latitude) then theta(ww) = !pi/2. - theta(ww)
endif
return,transpose([[r],[theta],[phi]])
end