Scenario: I have a map with a marked location on it. I know my $x,y$ coordinates on the map (top left corner is $0,0$), my distance from that marked location, my heading angle relative to true north ($0^\circ$ is north, $90^\circ$ is east, $180^\circ \rm S$, and $270^\circ \rm W$), and my bearing (bearing here meaning the angle I have to turn in order to be facing the marked location.

Imagine a half-circle sonar with $0^\circ$ on left, a ping of $35^\circ$ means I turn that angle to face the ping). I also know the $x,y$ coordinates of a point on the map I'm trying to get to, but I need to find out my distance to that point, and the heading I should be at to go straight towards that point.


  • 3 points: my location, marked location, location I'm trying to get to.
  • distance from my location to marked location
  • My heading and the bearing from my location to the marked location

Trying to find

  • distance from my location to location I'm trying to get to
  • heading I should have to reach the location I'm trying to get to

In the poorly drawn image below: $\color{red}{\text{Red dot}}$ is my location. $\text{Black dot}$ is marked known location. $\text{Black line}$ is distance between red and black dot. Small Orange line is my heading ($45^\circ$ let's say). My bearing to the $\text{black dot}$ is $35^\circ$. I need to find the distance from the $\color{red}{\text{red dot}}$ to the $\color{green}{\text{green dot}}$, and the angle from the $\color{red}{\text{Red dot}}$'s heading (orange line) to the $\color{green}{\text{green dot}}$ (dotted line).

enter image description here

So, finding the distance should just be the normal distance formula right? However, the angle part is confusing me. I've been banging my head against the desk trying to figure this out. Would I have to make a right triangle using the $\color{red}{\text{red dot}}$, $\color{green}{\text{green dot}}$, and East ($90^\circ$)?

  • $\begingroup$ Would best bet be to make a right triangle out of one of the directional angles i.e. East, find the angle using inverse of tangent with the opposite and adjacent sides of the triangle (known from x,y coordinates of each, could use cos/sin too), then subtract that from the heading ? $\endgroup$
    – pfinferno
    Jan 14 '15 at 19:19

Let your position be $x_0, y_0$ and your heading angle be $\alpha$ where due north has $\alpha = 0$.

Then a unit vector in your heading direction (the orange line) will be $\sin \alpha \hat{x} + \cos \alpha \hat{y}$. And a unit vector toward your green dot at $(x,y) = (x_0 + \Delta x,y_0 + \Delta y)$ will be $\frac{1}{R} (\Delta x \hat{x} + \Delta y \hat{y})$ where $R$ is the distance $R = \sqrt { (\Delta x)^2 + (\Delta y)^2}$.

Then the cosine of the bearing angle $\beta$ between the orange heading line and the dotted direction line is given by the dot product of those two unit vectors. $$ \cos \beta =\frac{1}{R} \left( \Delta x \sin \alpha + \Delta y \cos \alpha\right) \\ \beta =\cos^{-1} \frac{\Delta x \sin \alpha + \Delta y \cos \alpha}{R} $$


You know red and green dots locations respectively as the present position and target points: $$ (x_1,y_1),(x_2,y_2)$$ Distance between them: $$ d= \sqrt{(y_2-y_1)^2+(x_2-x_1)^2}$$ Use $atan2$ to find direction (automatically sensitive to signs of quadrant you are in, and the target location) $$ \theta_{relative}= atan2 \dfrac{y_2-y_1}{x_2-x_1}$$ then extra pinging angle: $$ \theta_{Orange Heading}(35^{\circ}) + 90^{\circ}-\theta_{relative} $$

Please check the above, because trigonometrical angles are measured counterclockwise and the heading rotation you gave are clockwise.


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.