# Conversion from Spherical Coordinates to Cartesian Coordinates aligned along arbitrary polar axis

I have spherical coordinates $w = (\theta, \phi)$ such that $\theta$ is the angle between $w$ and the polar axis (let's assume $z$ is up).

Assuming $w$ is a unit vector, the conversion to cartesian coordinates is: \left\{ \begin{align} x &= \cos(\phi) \sin(\theta) \\ y &= \sin(\phi) \sin(\theta) \\ z &= \cos(\theta) \end{align} \right.

I'd like to transform $w$ such that its polar axis lies on an arbitrary vector $n$, and then convert to cartesian coordinates. The end goal is to generate a hemisphere point cloud about the normal vector $n$, but when generating random variables, it is most convenient to initialize them in $z$-up space.

Rodriguez's formulation via Rotating one 3d-vector to another makes sense if we are going from Cartesian->Cartesian but is there a more efficient way to do it, maybe rotating the Spherical coordinates directly before converting to cartesian coords?

Thanks.

• Standard names for your spherical coordinates: $\theta$ is colatitude and $\phi$ is longitude. – Sammy Black Dec 13 '13 at 8:06