How can i calculate the bearing or the angular relationship between two points in a form in terms of degrees
Printable View
How can i calculate the bearing or the angular relationship between two points in a form in terms of degrees
Aren't two points always connected by a straight line? So it could be 0, 180, 360...
That's right.Quote:
Originally Posted by RhinoBull
You'll need a third point (or vector) to get an angle.
This gives the bearing from one point on a flat 2D plane to another point, relative to the plane's 'north'.X and Y are the relative dX and dY between both points.vb Code:
Public Const Pi As Double = 3.14159265358979 Public Const Pi2 As Double = 3.14159265358979 * 2# Public Const DegRad As Double = 3.14159265358979 / 180# Public Const RadDeg As Double = 180# / 3.14159265358979 Public Function ATan2(ByVal X As Double, ByVal Y As Double) As Double Dim sY As Double Dim sX As Double If Y < 0# Then sY = -Pi Else sY = Pi If X = 0# Then ATan2 = sY * 0.5 Else If X < 0# Then sX = sY Else sX = 0# ATan2 = Atn(Y / X) + sX End If ' If ATan2 < 0 Then ATan2 = ATan2 + Pi2 End Function
The positive Y axis is north, the positive X axis is east.
The result is in radians.
Multiply by RadDeg to get the result in degrees.
(multiply by DegRad to do the opposite)
If you are working on the surface of a sphere or in 3D space then you'll need different methods.
Thanks i will try it out