# Angle between 2 points, based off north

• Apr 6th 2009, 12:58 AM
JamesUK3000
Angle between 2 points, based off north
Hi people,

Basically I have 2 points, I know both of the point's X and Y co-ordinates.
I am wanting to find the angle between the 2 points based off of North. (0 degrees)

Pic: http://i44.tinypic.com/292o27d.jpg

In the picture, the angle i'm after would be roughly midway between 270 and 360 (315)

Sorry if i've posted this in the wrong section, i've really got no idea if this is trigonometry, geometry or what lol.

Thanks,
James
• Apr 6th 2009, 01:23 AM
Russ
Do the lines you've drawn there come from the origin (0,0)?
• Apr 6th 2009, 01:26 AM
Russ
Gonna assume they do and answer anyway.

Calling the blue dot "A" and the green dot "B".

To find the angle you need to use trig. To use trig you need a right angled triangle. How can you form a right angled triangle from that diagram?

How can you determine the side lengths of the triangle you draw? Well, given you know the co-ordinates of A and B you should consider that when you create your triangle.
• Apr 6th 2009, 01:26 AM
JamesUK3000
Sorry im not sure what you mean by the origin, but both points can be at any x and y position.
• Apr 6th 2009, 01:27 AM
Russ
>>I know both of the point's X and Y co-ordinates.
>>both points can be at any x and y position

Which one?
• Apr 6th 2009, 01:31 AM
JamesUK3000
ah sorry, i meant that i will be able to retrieve both point's X and Y position.

When I said they can be at any pos, i meant that i will know that pos, but it will not always be the same pos (in different occuraces ofcourse.)
Just realised that wasn't really relevant, basically I will always know both of the point's X and Y co-ordinates.
• Apr 6th 2009, 01:42 AM
JamesUK3000
Hi again,
managed to make a right angle triangle and figure out 2 side's lengths:
http://i42.tinypic.com/2rnwox5.jpg

I guess i need to find the hypotenuse length aswell? If so, would I do this using Pythagoras?

And then how would I get the angle im after using those lengths?

thanks
• Apr 6th 2009, 06:43 AM
Soroban
Hello, James!

We have two points: .$\displaystyle P(x_1,y_1),\;Q(x_2,y_2)$
. . and we want the bearing of $\displaystyle PQ.$

If $\displaystyle P$ and $\displaystyle Q$ can be any two distinct points, the formula is not simple.

Code:

        |                Q         |                o (x2,y2)         |              * :         |            *  :         |          *    :         |        *      :         |      *        : y2-y1         |    *          :         |  *            :         | *  θ            :       P o - - - - - - - - o     (x1,y1)    x2-x1      R
Let $\displaystyle \theta \,=\,\angle QPR.$

Then: .$\displaystyle \tan\theta \:=\:\frac{QR}{PR} \:=\:\frac{y_2-y_1}{x_2-x_1}$

Hence: .$\displaystyle \theta \;=\;\arctan\left(\frac{y_2-y_1}{x_2-x_1}\right)$

But the bearing of $\displaystyle QR$ depends on the "quadrant" of $\displaystyle Q$, relative to $\displaystyle P.$

I think I've organized it into two cases:
. . whether $\displaystyle Q$ is to the right or left of $\displaystyle P.$

. . . . . $\displaystyle \begin{array}{|c|c|} \hline x_2-x_1 & \text{Bearing} \\ \hline \hline + & 90^o - \theta \\ \hline - & 270^o - \theta \\ \hline \end{array}$

But someone check my work . . . please!
.
• Apr 9th 2009, 08:43 AM
JamesUK3000
Thanks soroban, worked perfectly!

For any lua scripters out there:
Code:

function VLEGetBearingOf2Points(Point1X, Point1Y, Point2X, Point2Y)         local SideYLength = Point2Y - Point1Y         local SideXLength = Point2X - Point1X                 if SideYLength == 0 and SideXLength == 0 then return 0         end                 local TanValue = SideYLength / SideXLength         local Radians = math.atan(TanValue)                 local Angle = math.deg(Radians)                 local a = Point2X - Point1X         if a >= 0 then Angle = 90 - Angle         else Angle = 270 - Angle         end                 return Angle end