[Math] How to calculate the distance between two points with polar coordinates

calculus

points in image

I want to calculate the distance between $p_{1}$ and $p_{2}$ as shown in the image. These points are in a polar coordinate space. The red arrows in the image show in which direction $\rho$ and $\theta$ "grow".

$p_{1}$ = $(\rho_{1},\theta_{1})$ and $p_{2}$ = $(\rho_{2},\theta_{2})$.

In both cases, $\theta \epsilon [0,180ยบ]$ and $\rho \epsilon [0,\rho_{max}]$.

$\rho_{max}$ is the size of the diagonal of the black square.

I've tried to use the euclidean distance formula for polar coordinates:

$d(a,b) = \sqrt{\rho_{1}^2 + \rho_{1}^2 – 2\rho_{1}\rho_{2}\cos(\theta_{1}-\theta{2})}$.

However, the value calculated does not seem to be correct.

I've tried to calculate this distance using this formula:

$d(a,b) = \sqrt{(\rho_{1}-\rho_{2})^2 + \sin(\theta_{1}-\theta{2})^2}$

Then it occured to me that I might have to normalize $\rho$, so it can only take values between zero and one (just like the $\sin$). Thus, both coordinates have the same weight.

Is this a correct way to calculate the distance between these two points?

Best Answer

Consider the cosine law:

$$ c^2 = a^2 + b^2 - 2\cdot a\cdot b\cdot cos\left(\theta\right) $$

which gives the length of 3rd side $c$ in a triangle with legs $a$ and $b$ that are separated by angle $\theta$. The legs $a$ and $b$ correspond to points $\left(r_1,\theta_1\right)$ and $\left(r_2,\theta_2\right)$ drawn as vectors from the coordinate origin, with respective lengths $r_1$ and $r_2$ and separated by angle $\theta = \theta_2-\theta_1$. The cosine law then becomes an expression for the distance $d$ between the points:

$$ d^2 = {r_1}^2 + {r_2}^2 - 2\,r_1\,r_2\,cos\left(\theta_2-\theta_1\right) $$

Notice that difference $\theta_1-\theta_2$ would give identical results since $cos\left(\theta\right) = cos\left(-\theta\right)$. While for triangles the separation angle is always $\theta < 180^\circ$, the symmetry of the cosine function holds for larger angles as well. I would ask the original poster to give more information about the code that uses this correct equation, verify its implementation, and the values of equation inputs.

The polar distance equation can also be derived from the Euclidean distance in Cartesian coordinates:

$$\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2} $$

By substituting $x = r\cdot cos(\theta)$ and $y = r\cdot sin(\theta)$ for the coordinates $(x_1,y_1)$ and $(x_2,y_2)$ we get

$$d^2 = \left[r_2\,cos(\theta_2)-r_1\,cos(\theta_1)\right]^2 + \left[r_2\,sin(\theta_2)-r_1\,sin(\theta_1)\right]^2 $$

expand and simplify using $cos^2(\theta)+sin^2(\theta)=1$

$$d^2 = {r_1}^2 + {r_2}^2 - 2\,r_1\,r_2\,\left[cos(\theta_1)\,cos(\theta_2)+sin(\theta_1)\,sin(\theta_2) \right]$$

simplify further using $cos(\alpha-\beta) = cos(\alpha)\,cos(\beta) + sin(\alpha)\,sin(\beta)$

$$ d^2 = {r_1}^2 + {r_2}^2 - 2\,r_1\,r_2\,cos\left(\theta_2-\theta_1\right) $$

which is the same as before. The original expression inside the cosine term confirms that $\theta_1$ and $\theta_2$ are interchangeable.

EngrStudent's answer is misleading because $d^2 = \left(\Delta r\right)^2 + \left(r\Delta\theta\right)^2$ so the terms $\Delta r = {r_1}^2+{r_2}^2$ should not cancel out. The result for $\left(r\Delta\theta\right)^2$ is accurate but not the Euclidean distance, unless both points happen to have the same radius as in the example on the unit circle ($\Delta r = 0$). The distance $r\Delta\theta$ also vanishes when $r_1$ or $r_2$ is zero, unlike the cosine law.

SchrodingersCat's answer is correct as long as infinitesimal distances are used, but the extension to finite distance is wrong as indicated by the ambiguous definition of $r$. Extending the increment $dl$ to a finite distance $l$ requires solving $\int_{A}^{B} dl $ along a straight line between points A and B, which should give the same result.

Related Question