# Distance between two points in spherical coordinates

I want to find the distance between two points in spherical coordinates, so I want to express $||x-x'||$ where $x=(r,\theta, \phi)$ and $x' = (r', \theta',\phi')$ by the respective components. Is this possible? I just know that this is $\sqrt{r^2+r'^2-2rr'\cos(\theta- \theta')}$ if $\phi,\phi'$ is the same, but what is the most general distance?

• Probably the most easy thing to do would be to convert both points to Cartesian co-ordinates, subtract them and take the length of that vector. Jun 13, 2014 at 15:39
• yes, but i really don't want to do this.
– user66906
Jun 13, 2014 at 15:41
• Why not? Surely if it's easier and more efficient then there's no reason to do otherwise? Jun 13, 2014 at 15:41
• No, it is not more efficient, cause I need to integrate over this and use this spherical symmetry.
– user66906
Jun 13, 2014 at 15:51
• @Hippalectryon, I understand that the OP is interested in the distance along a straight line but your link explains how to calculate the distance along a great-circle. Mar 11, 2017 at 1:39

The expression of the distance between two vectors in spherical coordinates provided in the other response is usually expressed in a more compact form that is not only easier to remember but is also ideal for capitalizing on certain symmetries when solving problems.

\begin{align} \|\mathbf{r}-\mathbf{r}^\prime\| &=\sqrt{(x-x')^2+(y-y')^2+(z-z')^2}\\ &=\sqrt{r^2+r'^2-2rr'\left[\color{red}{\sin(\theta)\sin(\theta')}\color{blue}{\cos(\phi)\cos(\phi')}+\color{red}{\sin(\theta)\sin(\theta')}\color{blue}{\sin(\phi)\sin(\phi')}+\cos(\theta)\cos(\theta')\right]}\\ &=\sqrt{r^2+r'^2-2rr'\left[\color{red}{\sin(\theta)\sin(\theta')}\color{blue}{\left(\cos(\phi)\cos(\phi')+\sin(\phi)\sin(\phi')\right)}+\cos(\theta)\cos(\theta')\right]}\\ &=\sqrt{r^2+r'^2-2rr'\left[\color{red}{\sin(\theta)\sin(\theta')}\color{blue}{\cos(\phi-\phi')}+\cos(\theta)\cos(\theta')\right]}.\\ \end{align}

This form makes it fairly transparent how azimuthal symmetry allows you to automatically eliminate some of the angular dependencies in certain integration problems. Another advantage of this form is that you now have at least two variables, namely $$\phi$$ and $$\phi'$$, that appear in the equation only once, which can make finding series expansions w.r.t. these variables a little less of a pain than the others.

• It should be noted that this formula uses phi as the azimuthal angle and theta as the polar angle (as there also exists the convention where the are swapped). Jun 15, 2018 at 3:14
• This seems interesting, but odd to me. So, on a unit sphere, looking at the point (1,0°,0°), the distance from any point is $\sqrt{2-2cos\theta '}$? This doesn't seem right somehow, how does the other coordinate not count? May 3, 2021 at 11:14
• @toorelevant The point (1,0°,0°) corresponds to the Cartesian point (0,0,1). Think of it as the north pole of the unit sphere. Any points on the same circle of latitude should have the same distance to the north pole. Nov 9, 2021 at 17:38
• @HaoS See my previous comment. Nov 9, 2021 at 17:44

You have simply to write it in Cartesian coordinates and change variables: $x=r\sin(\theta)\cos(\phi)$, $y=r\sin(\theta)\sin(\phi)$, $z=r\cos(\theta)$ $$\sqrt{(x-x')^2+(y-y')^2+(z-z')^2}=$$$$=\sqrt{r^2+r'^2-2rr'\left[\sin(\theta)\sin(\theta')\cos(\phi)\cos(\phi')+\sin(\theta)\sin(\theta')\sin(\phi)\sin(\phi')+\cos(\theta)\cos(\theta')\right]}$$ But I don't see a way to really improve this mess.

Building on the answer from @[David H], I wrote the distance in a way that highlights the difference in angles: $$||\vec r_1 - \vec r_2|| = \sqrt{ {r_1}^2 + {r_2}^2 - 2\, r_1 r_2 \cos(\theta_1 - \theta_2) - 2\, r_1 r_2 \sin \theta_1 \sin \theta_2 \left( \cos(\phi_1 - \phi_2) - 1 \right) }$$ It highlights the contributions from the difference in polar angle $\theta$ and the difference in the azimuthal angle $\phi$, (third and fourth terms, respectively, under the square root symbol). Note the intuitive scaling of the azimuthal contribution by $\sin \theta_1 \sin \theta_2$. Of course, when the angular differences are both $0$, the distance reduces to $||r_1-r_2||$.