0
$\begingroup$

In a polar coordinates system I have two point $P_1$ and $P_2$. For $P_1$ I know it coordinates from the origin ($O$) which are $(d_1,\alpha_1)$.

For $P_2$ I also know it's coordinates, $(d_2,\alpha_2)$, but it's from $P_1$. I want the coordinate of $P_2$ from the origin, $(D,A)$.

schem

I've found some post about translation in polar coordinates.

The first one gives those equations:

$$d_2^2 = d_1^2 + D^2 + 2d_1D \cos(A-\alpha_1)~~~~~~~~~~~~~~~~(1)$$

and

$$\sin(\alpha_2) = \frac{D}{d_2} \sin(A-\alpha_1)~~~~~~~~~~~~~~~~(2)$$

The second one gives those equations (I guessed some parts because he gave it with value instead of variables names):

$$(1)$$

and

$$ \tan(\alpha_2) = \frac{D \sin(A-\alpha_1)}{D \cos(A-\alpha_1)-d_1}~~~~~~~~~~~~~~~~(3)$$


My problem is, from all those equations, I don't know how to get $D$ and $A$.

EDIT: I have to do it several times, so I'd like a solution with a small computational cost (lower than use the cartesian coordinates)

$\endgroup$

3 Answers 3

1
$\begingroup$

In the linked questions, the distances and directions from the origin of two points are known and we want the distance and direction between them. That is, in terms of your figure, $d_1, \alpha_1, D,$ and $A$ are known while $d_2$ and $\alpha_2$ are unknown.

Your problem is set differently because you already know the distance and direction between the two points that are not the origin. What you are missing is the distance and direction from the origin to one of those points.

But by understanding a little bit about why the other solutions work, you can reapply them to your different problem.

The Law of Cosines relates the length of one side of a triangle (on one side of the equation) to the angle opposite that side and to the lengths of the other two sides (on the other side of the equation).

The Law of Sines relates the ratio of a side and the angle opposite it to the ratio of another side and the angle opposite it. This is a multipurpose formula, because if you know two ratios are equal, $p/q = u/v,$ and you know any three of the quantities in the ratios, you can easily solve for the fourth quantity.

The Law of Cosines in general can be written $$ c^2 = a^2 + b^2 - 2ab \cos \theta, $$ where $a,$ $b,$ and $c$ are lengths of sides of a triangle and $\theta$ is the interior angle opposite $c.$

Since $D$ is your unknown side, you want to put $D$ for $c.$ Therefore you put $d_1$ and $d_2$ for $a$ and $b.$ Now the trickiest part of the application is that the Law of Cosines deals with the interior angle opposite the unknown side, but you have the exterior angle $\alpha_2.$ So just be aware that if $\theta$ is the interior angle, then $\theta = \pi - \alpha_2$ and $\cos\theta = - \cos\alpha_2.$ So when you make all these substitutions into the Law of Cosines you get $$ D^2 = d_1^2 + d_2^2 + 2 d_1 d_2 \cos \alpha_2. $$

Since $D$ is positive (assuming you want the usual polar coordinates, with positive radius), you can take the square root to solve for it without using a $\pm$ sign: $$ D = \sqrt{d_1^2 + d_2^2 + 2 d_1 d_2 \cos \alpha_2}. $$

This works in every case, even if $\alpha_2$ obtuse or if the direction of the angle is counterclockwise instead of clockwise (including the case where you measure $\alpha_2$ in such a way that it is greater than $180$ degrees).

The Law of Sines says $$ \frac{\sin P}{p} = \frac{\sin Q}{q} $$ where $P$ and $Q$ are angles of a triangle and $p$ and $q$ are the lengths of the sides opposite $P$ and $Q$ respectively. Note that the sine of an exterior angle is equal to the sine of the interior angle, so you can use interior or exterior angles interchangeably in this formula. Therefore you can write

$$ \frac{\sin (A - \alpha_1)}{d_2} = \frac{\sin \alpha_2}{D}. $$

Multiply both sides by $d_2,$ take the inverse sine of both sides, and add $\alpha_1$, and the result is

$$ A = \alpha_1 + \arcsin\left(\frac{d_2\sin \alpha_2}{D}\right). $$

Now you have only one thing to watch out for, which is that this solution for $A$ assumed that the angle $A - \alpha_1$ was acute. That is a drawback to the first solution you found. You can use Law of Cosines on $A - \alpha_1$ to disambiguate whether it is acute or obtuse, but now you have additional calculations to perform.

The second solution is better but can be improved further for use in a program by using the $\mathrm{atan2}$ function. The idea is that you construct a right triangle and solve for the angle; in your case you can take $d_1 + d_2 \cos\alpha_2$ as one side of the triangle and $d_2\sin\alpha_2$ as the other side. Then $$ A = \alpha_1 + \mathrm{atan2}(d_2\sin\alpha_2, d_1 + d_2 \cos\alpha_2). $$

This works even if $\alpha_2$ is obtuse or greater than $180$ degrees, as long as you measure all the angles $\alpha_1,$ $\alpha_2,$ and $A$ in the same direction, for example clockwise as in your figure.

None of these formulas particularly cares which quadrant of the plane any of the points are in or which points are "above" which other points.

$\endgroup$
5
  • $\begingroup$ I'm not a mathetician, I'm just a computer engineer trying to do some math stuff, that why I was not able to do the transformation. :s Thanks a lot for your explenations :) And about the sign of $D$. my figure is an example. If $P_2$ is below $P_1$ or $O$, how can I know it ($D<0$ or $A<\pi$, or something else)? $\endgroup$
    – Phantom
    Oct 2, 2019 at 13:04
  • $\begingroup$ In that light the second solution you found has a better idea. I have added this to the answer, but I use $\mathrm{atan2}$ rather than $\arctan$ because $\arctan$ does not give you the correct angle when the correct angle would be obtuse. $\endgroup$
    – David K
    Oct 2, 2019 at 13:32
  • $\begingroup$ I can have positive and negative angles. But positive angles are always clockwise, and negative always conter-clockwise. Is it what you mean? As a next step of computation I use $P_2$ as the center of transformation for the rest of the scene. And after a while, all the scene is upside-down, because equations from linked questions don't care about the sign. Please, could you give a little more info about the way you got your last equation, like this, as an exercice, I could try to find the good equation $\endgroup$
    – Phantom
    Oct 2, 2019 at 14:03
  • $\begingroup$ So in your system an angle of $-\theta$ is in the opposite direction from the angle $\theta.$ That is what I would consider "all angles measured in the same direction", so you should have no problem there. I have not had time to do a full writeup of the last equation yet; I think you would probably want to see at least three separate cases for positive angles and also consider negative angles. $\endgroup$
    – David K
    Oct 3, 2019 at 3:53
  • $\begingroup$ Anyway, I found it ($\alpha_2 = \mathrm{atan2}(D\sin(A-\alpha_1), D\cos(A-\alpha_1)-d_1)-\alpha_1$, if anyone need it). Thanks again for your post ! ;) $\endgroup$
    – Phantom
    Oct 3, 2019 at 11:12
1
$\begingroup$

Consider the following right triangle $\triangle{P_1 Q P_2}$

image

The sides of the triangle are known $$ \begin{aligned} x & = d_2 \cos \alpha_2 \\ y & = d_2 \sin \alpha_2 \end{aligned} $$

Now you can find the properties of the larger triangle $\triangle{O Q P_2}$

$$\begin{aligned} D &= \sqrt{ (d_1+x)^2 + y^2 } \\ A &= \alpha_1 + \tan^{-1} \left( \frac{y}{x+d_1} \right) \end{aligned} $$

$\endgroup$
3
  • $\begingroup$ I like your solution. I just let it open for somes days to see if someone else has an other solution. Thanks $\endgroup$
    – Phantom
    Oct 2, 2019 at 12:45
  • $\begingroup$ I have a personal axiom, that find the right triangle in any problem and the solution becomes trivial. $\endgroup$ Oct 2, 2019 at 12:48
  • 1
    $\begingroup$ The solution for $D$ is essentially a proof of the Law of Cosines. $\endgroup$
    – David K
    Oct 2, 2019 at 12:56
0
$\begingroup$

You could transform $(d_1, \alpha_1)$ and $(d_2, \alpha_2)$ into cartesian coordinates, add them to get the cartesian coordinates of $P_2$ and then transform them back into polar coordinates.

$\endgroup$
1
  • $\begingroup$ I have to do several times, so I'd like a way with a small computational cost. I forgot to mention it in my post. But thanks $\endgroup$
    – Phantom
    Oct 2, 2019 at 12:33

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.