# Convert from Cartesian to Spherical Coordinates with different reference vectors

I currently have a set of points in their Cartesian form $(x, y, z)$. I need to perform an operation on these points to convert them to Spherical coordinates.

The problem is, the normal reference vectors for conversion are $(0, 0, 1)$ and $(1, 0, 0)$ allowing us to use the following equations to calculate the angles:

$R = \sqrt{x^2 + y^2 + z^2}$

$\theta = \cos^{-1}\left(\frac{z}{R}\right)$

$\phi = \tan^{-1}\left(\frac{y}{x}\right)$

In my case, the reference vectors will be different from the Cartesian coordinate system (so not $(0, 0, 1)$ and $(1, 0, 0)$) and the origin will also be some arbitrarily defined point, say $(x', y', z')$.

I have considered first shifting the points in the Cartesian coordinate system so that the origins are equal by doing the following:

$l = (x-x', y-y', z-z')$

I could then rotating all of the points so that the reference vectors are also equivalent. I know this can be done but I haven't worked out the math on this yet.

My question is: Does there exist some generalized conversion equations from Cartesian to Spherical coordinates that takes into account potentially different reference vectors and origins?

• Hello. Friendly advice: Please use LaTeX markup which will greatly improve readability. You will get more answers this way. – The Count Dec 1 '16 at 21:07
• Thanks for the tip. I converted some stuff to LaTeX and added some more details. – wmaxlees Dec 1 '16 at 22:40

When you say that $(x,y,z)$ is relative to different reference vectors, you mean that this vector is $x\textbf{a} + y\textbf{b} + z\textbf{c} + (x',y',z')$ where $\textbf{a,b,c}$ are basis vectors which can be written as:

$\textbf{a} = a_1(1,0,0) + a_2(0,1,0) + a_3(0,0,1)$

$\textbf{b} = b_1(1,0,0) + b_2(0,1,0) + b_3(0,0,1)$

$\textbf{c} = c_1(1,0,0) + c_2(0,1,0) + c_3(0,0,1)$

and $(x',y',z')$ is your arbitrary origin.

We'll think about going from the standard Cartesian coordinates into the coordinates you're got set up, and then find an inverse.

If $(u,v,w)$ is the vector of a point with respect to the standard Cartesian coordinates, then the vector with respect to this new basis is given by the matrix expression:

$\left( \begin{array}\ x \\ y\\ z\end{array} \right) = \left( \begin{array}\ a_1 & a_2 & a_3 \\ b_1 & b_2 & b_3 \\ c_1 & c_2 & c_3 \end{array} \right) \left( \begin{array}\ u \\ v\\ w\end{array} \right) + \left( \begin{array}\ x' \\ y'\\ z'\end{array} \right)$

So to get back into standard Cartesian coordinates, you need to find the inverse of that matrix, and apply it to $\left( \begin{array}\ x-x' \\ y-y'\\ z-z'\end{array} \right)$. Then you can use the standard formula you've stated above on the resulting expression to move into spherical polars.

Alternatively, you could just redefine the angles $\phi, \theta$ so as to avoid having to rotate the coordinate system back to the standard one (although your basis vectors would need to be perpendicular and unit length in order for this to work)

Hope this helps :)