Graph a line oriented by an specific angle?

58 Views Asked by At

I'm writing a software that plots gps data on a map, and so far it has been riddled with complex math problems, many of which I was able to fix by myself but this one I can't figure out.

The software plots vehicles on the map, each vehicle is represented by an icon of a car.

The lat/lon coordinates from the gps input are converted into X, Y.

So, considering that a car is at $x=100$/$y=100$, and its heading is provided in Degrees (where 0 is north, or the top of the screen), what is the math formula I could use to draw a line starting at those coordinates pointing to the heading provided?

Thanks in advance.

1

There are 1 best solutions below

0
On BEST ANSWER

If you want a line of length $d$, then it should start at $(x_0,y_0)$ and end at $(x_1,y_1)$, where

$(x_0,y_0)$ are the coordinates of the car
$x_1 = x_0 + d\sin\theta$
$y_1 = y_0 + d\cos\theta$
$\theta$ is the angle where the car is heading (in radians)

In the formula for $y_1$, you may have to change the "$+$" to "$-$", depending on which way your coordinate system is oriented. In many graphics environments, $y$ increases as you move down the screen. Also, remember to convert degrees to radians before you call the sine and cosine functions.