Compute absolute bearing between two points $2D$

1.4k Views Asked by At

Considering the following situation

bearing

bearing2

What is the formula to compute the absolute bearing between the heading of the central robot and the position (x and y coordinates) of the lower-left robot?

Considering we are in a cartesian plan with horizontal x-axis and vertical y-axis.

Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

This is how I understand your question:

  1. The central robot has coordinates $(x_0,y_0)$ and a heading $\alpha$ in degrees defined in the manner shown in your second figure.
  2. The other robot has coordinates $(x_1,y_1)$.
  3. You want to know the angle in degrees between the heading of the central robot and the other robot, where the angle is measured clockwise from the heading of the central robot.

Set $dx=x_1-x_0$, $dy=y_1-y_0$ and $d=\sqrt{dx^2+dy^2}$. Assuming $d \neq 0$ calculate $$\theta = \frac{180}{\pi}\arccos \left(\frac{dx}{d}\right)$$ If $dy \lt 0$ then set $$\theta = 360-\theta$$ This is the angle in the interval $[0,360[$ measured counterclockwise from the positive x-axis centered at $(x_0,y_0)$ to the other robot. I.e. the angle is given in the customary math system where $0^\circ$ is along the positive x-axis.

Convert the heading of the central robot to the customary system: $$\alpha' = 90 - \alpha$$ If $\alpha' \lt 0$ then $\alpha' = 360 + \alpha'$.

And find the final angle: $$\theta' =\alpha'-\theta$$ If $\theta' \lt 0$ then $\theta' = 360 + \theta'$.