Do the lines you've drawn there come from the origin (0,0)?
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)
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.
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.
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.
managed to make a right angle triangle and figure out 2 side's lengths:
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?
We have two points: .
. . and we want the bearing of
If and can be any two distinct points, the formula is not simple.
LetCode:| Q | o (x2,y2) | * : | * : | * : | * : | * : y2-y1 | * : | * : | * θ : P o - - - - - - - - o (x1,y1) x2-x1 R
But the bearing of depends on the "quadrant" of , relative to
I think I've organized it into two cases:
. . whether is to the right or left of
. . . . .
But someone check my work . . . please!
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