### Spherical coordinates

First of all, we have
$\hat{r}=\sin\theta \cos\varphi \hat{x} + \sin\theta \sin\varphi \hat{y} + \cos\theta \hat{z}\\ \hat{\varphi}=-\sin\varphi \hat{x} + \cos\varphi{y}\\ \hat{\theta}=\hat{\varphi}\times \hat{r}= \cos\theta \cos\varphi \hat{x} +\cos\theta \sin\varphi \hat{y} - \sin\theta \hat{z}$
Let now $\hat{x}=a_1\hat{r}+a_2+\hat{\theta}+a_3\hat{\varphi}$, then
$a_1=\hat{x}\cdot\hat{r}=\sin\theta \cos\varphi\\ a_2=\hat{x} \cdot\hat{\theta}=\cos\theta \cos\varphi\\a_3=\hat{x}\cdot\hat{\varphi}=-\sin\varphi$
Similarly for $\hat{y}$ and $\hat{z}$.