Converting from one coordinate system to another?

In using the CoordinateTransformData[] and CoordinateTransform[] commands I get totally different results from what I expect (see attached), and I can not understand why. In reviewing the documentation, it appears that I am using the commands for the right purpose, but they don’t seem to give the correct answer.

I always prefer to use different techniques to verify my answers and find it somewhat troubling that I am getting two different answers. Could someone please tell me what I am doing incorrectly.

Thanks,

Hi Mitchell,

The short answer is that you are using a slightly different convention for spherical coordinate than what is in Wolfram Language.

CoordinateTransform[{"Spherical" -> "Cartesian", 3}, {\[Rho], \[Theta], \[Phi]}]

shows that theta and phi role are switch in your equations and CoordinateTransform.

Slightly longer answer, unfortunately, in the example you have provided, you cannot simply switch theta and phi

CoordinateTransformData["Spherical" -> "Cartesian", "Mapping", {12, 0, Pi/4}]

because spherical has a range assumption

In[55]:= CoordinateChartData["Spherical", "CoordinateRangeAssumptions"]

Out[55]= #1[[1]] > 0 && 0 < #1[[2]] < \[Pi] && -\[Pi] < #1[[3]] <= \[Pi] &

but this will give the desired output:

CoordinateTransformData["Spherical" -> "Cartesian", "Mapping", {12, \[Theta], Pi/4}] /. \[Theta] -> 0

Hope this helped.

You may have reversed the meaning of theta and phi.