How to calculate the distance between two points with polar coordinates?

$\begingroup$

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?

$\endgroup$ 4

3 Answers

$\begingroup$

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.

$\endgroup$ 1 $\begingroup$

In Euclidean geometry, we have where $dl$ is the distance, we have $$dl^2=dx^2+dy^2$$

In polar co-ordinates, we have $$x=r\cos \theta$$ $$y=r\sin \theta$$ So $$dx=dr\cos \theta-r\sin \theta d\theta$$ and $$dy=dr\sin \theta+r\cos \theta d\theta$$

Put these values in the first equation and we have $$dl^2=(dr\cos \theta-r\sin \theta d\theta)^2+(dr\sin \theta+r\cos \theta d\theta)^2$$ $$=(dr)^2+(rd\theta)^2$$

So the distance between 2 points P($r_1,\theta_1$) and Q($r_2,\theta_2$) is given by $$l=\sqrt{(r_2-r_1)^2+r^2(\theta_1-\theta_2)^2}$$

$\endgroup$ 5 $\begingroup$

SchrodingersCat made a nice answer, but it has not been updated in a year and a half and is missing a term, and an actual answer. (The answer is one we should know both from Algebra and from Trigonometry.)

$$dl^2 = \left( dr\right)^2 + \left(rd\theta \right)^2$$

$$\Delta l^2 = \left( \Delta r\right)^2 + \left(r \Delta \theta \right)^2$$

now we evaluate this between 1 and 2

$$ \Delta l^2 \rvert^2_1= \Delta r^2\rvert^2_1 + \left(r \Delta \theta \right) ^2\rvert^2_1$$

so how is $r$ in the $\left(r^2 \Delta \theta ^2 \right) \rvert^2_1$ handled? Do we evaluate r at the same place we evaluate theta? Should the answer look like this?

$$ \Delta l^2 \rvert^2_1= \left(r_2 - r_1 \right)^2 + \left(r_2 \theta_2 - r_1 \theta_1 \right)^2 $$

if we think of two points on a unit circle at $\theta = \left[0,\pi\right]$ then the distance between the points is 2 and the square of that is 4. When we use this expression what do we get? We get a value we know is not correct.

enter image description here

Though they had their misconceptions about 3.0, even 1800's era politicians were sure that $\pi$ was not equal to 2.

Why not resort to the law of cosines, from algebra?

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

where ABC is the triangle with side AC of length b, side CB of length a, and angle AC to CB of size C. When we try it on the previously given points we get this:

enter image description here

It seems to work. I'm pretty sure that $2 = 2$.

Inspection tells us that, if derivation was correct, we can say this

$$\left[ \left( \Delta r\right)^2 + \left(r \Delta \theta \right)^2 \right] \rvert^2_1 = r_2^2 + r_1^2 - 2 \cdot r_1 \cdot r_2 \cdot cos \left(\theta \right)$$

expanding out the $\Delta r$ and isolating the $r \Delta \theta$ yields

$$\left(r \Delta \theta \right)^2 \rvert^2_1 = r_2^2 + r_1^2 - 2 \cdot r_1 \cdot r_2 \cdot cos \left(\theta \right) - \left(r_2 - r_1 \right)^2$$

We then expand :

$$\left(r \Delta \theta \right)^2 \rvert^2_1 = r_2^2 + r_1^2 - 2 \cdot r_1 \cdot r_2 \cdot cos \left(\theta \right) - \left(r_2^2 - 2r_2r_1 + r^2_1\right)$$

then simplify

$$\left(r \Delta \theta \right)^2 \rvert^2_1 = - 2 r_1 r_2 cos \left(\theta \right) + 2r_2r_1 $$

We can then gether terms of $r$

$$\left(r \Delta \theta \right)^2 \rvert^2_1 = 2 r_1 r_2 \cdot \left(1- cos \left(\theta \right) \right) $$

We also know that "C" is really the interior angle $\theta_2 - \theta_1$ so this becomes: $$\left(r \Delta \theta \right)^2 \rvert^2_1 = 2 r_1 r_2 \cdot \left(1- cos \left(\theta_2 - \theta_1 \right) \right) $$

The left side of the expression is the unknown and the right contains only our known values.

Note: while I like the test case of $\vec{\theta} = \left[0,\pi \right]$, I think that a decent test would include cases such as $\vec{\theta} = \left[0,\frac{\pi}{2} \right]$ or $\vec{r} = \left[1,2 \right]$ as well. Multiple cases with different "physics" should be tested.

$\endgroup$

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like