# CoordinateTransform from Cartesian to Spherical

I have a set of coordinates on the sphere in terms of cartesian coordinates. I would like to convert them to spherical data points. However, when I try to convert the point {0, 0, 1} it tells me that the solution is indeterminate. Why is this?

CoordinateTransform[ "Cartesian" -> "Spherical", {0, 0, 1}]


ArcTan::indet: Indeterminate expression ArcTan[0,0] encountered. >>

Best, Andy

• This will work Limit[CoordinateTransform["Cartesian" -> "Spherical", {0, eps, 1}], eps -> 0]. – b.gates.you.know.what May 2 '13 at 16:00
• Hmm, okay, so I will hand tune the entries that I have close to {0,0,1}. In general is there better documentation on what the domains and ranges of these CoordinateTransforms actually is? I've had a difficult time finding it. – afurn May 2 '13 at 16:09
• Also, {0, 0, 1} /. v_?VectorQ :> With[{r = Norm[v]}, {r, Arg[#1 + I #2 & @@ Most[v]], ArcCos[Last[v]/r]}] – J. M.'s ennui May 2 '13 at 16:20
• Thanks J.M. that's very helpful. – afurn May 2 '13 at 16:38

Personally, I am still much happier using the older functionality that existed before version 9 and still exists in the newest version:

Quiet@Needs["VectorAnalysis"]

CoordinatesFromCartesian[{0, 0, 1}, Spherical]

(* ==> {1, 0, 0} *)


There are no errors in this case.

This has the advantage that your notebooks remain compatible with older versions. Also, the syntax of this package is less verbose (of course you first have to load the VectorAnalysis package, but that needs to be done only once).

It's indeterminate because $\varphi$ coordinate is undefined for case when $\theta=0$. You can set it to anything, and the point itself won't change. You can use the approach suggested in the comment by b.gatessucks:

Limit[CoordinateTransform["Cartesian" -> "Spherical", {0, eps, 1}], eps -> 0]
`
• But if I look at CoordinateTransform["Spherical" -> "Cartesian", {1, th, phi}] then this gives me a mapping from spherical coordinates to cartesian coordinates on the unit sphere. Namely, {Cos[phi] Sin[th], Sin[phi] Sin[th], Cos[th]}, which for the value phi=0=th I get the value {0,0,1} it seems strange I can't get the inverse of this using the same coordinate systems with the arrow going the other direction in CoordinateTransform. – afurn May 2 '13 at 16:20
• I don't quite understand what you mean by "arrow going the other direction". You can definitely transform from spherical to Cartesian coordinates, but you can't definitely do backwards in general. There are certain directions which admit any value for some coordinate in spherical coordinates. Namely, if you have Cartesian point $(0,0,z)$, your $\varphi$ coordinate for spherical coords is undefined. The same holds true for case $r=0$ in polar coords. – Ruslan May 2 '13 at 16:33