2
$\begingroup$

I am using Mathematica v9.0.1.0 and wanted to compare Mathematica's CoordinateTransformData command to Matlab's cart2sph. (Note that cart2sph is defined completely differently, and I need it in the other form, hence why I would like to check).

I will demonstrate my problem in the form of an example. In particular, for three randomly chosen coordinate points in cartesian (x, y, z) coordinates, I would like to have their spherical (r, theta, phi) coordinate representation.

I will paste the code in below:

CoordinateTransformData["Cartesian" -> "Spherical", "Mapping", {1, 2.0, 3}]
{3.74166, 0.640522, 1.10715}
CoordinateTransformData["Cartesian" -> "Spherical", "Mapping", {.4, 0.2, -1}]
{1.09545, 2.72106, 0.463648}

Both of the above are correct, but

CoordinateTransformData["Cartesian" -> "Spherical", "Mapping", {-0.6, 1.8, -4}]

prints the error message:

CoordinateTransformData::bdpt: Evaluation point {-0.6, 1.8, -4} is incompatible with the coordinate assumptions of the specified coordinate chart. >>

If I simply follow the definitions given on Wikipedia and write my own script:

comparcart2sphr[x_, y_, z_] := 
  {Sqrt[(x)^2 + (y)^2 + (z)^2], ArcCos[z/Sqrt[(x)^2 + (y)^2 + (z)^2]], ArcTan[x, y]}

then

comparcart2sphr[1, 2.0, 3]
{3.74166, 0.640522, 1.10715}
comparcart2sphr[.4, .2, -1]
 {1.09545, 2.72106, 0.463648}
comparcart2sphr[-.6, 1.8, -4]
{4.42719, 2.69868, 1.89255}

Can someone explain why Mathematica cannot handle this? I realise that this is because of the assumption they have in their chart, but surely it should be able to handle all points in R3. From the help file of CoordinateTransformData one could also write

mathematicahelpexpr[x_, y_, z_] := 
  {Sqrt[x^2 + y^2 + z^2], ArcTan[z, Sqrt[x^2 + y^2]], ArcTan[x, y]}

and obtain

mathematicahelpexpr[-.6, 1.8, -4]
{4.42719, 2.69868, 1.89255} 
$\endgroup$

1 Answer 1

1
$\begingroup$

Seems to be a bug in V9. In V10,

 CoordinateTransformData["Cartesian" -> "Spherical", "Mapping", {-0.6, 1.8, -4}]

returns

{4.42719, 2.69868, 1.89255}

as expected.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.