PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
bearing between two points-VBForums

# Thread: bearing between two points

1. ## bearing between two points

How can i calculate the bearing or the angular relationship between two points in a form in terms of degrees  Reply With Quote

2. ## Re: bearing between two points

Aren't two points always connected by a straight line? So it could be 0, 180, 360...  Reply With Quote

3. ## Re: bearing between two points Originally Posted by RhinoBull
Aren't two points always connected by a straight line? So it could be 0, 180, 360...
That's right.
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'.
vb Code:
`Public Const Pi  As Double = 3.14159265358979Public 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 DoubleDim sY As DoubleDim 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 + Pi2End Function`
X and Y are the relative dX and dY between both points.
The positive Y axis is north, the positive X axis is east.
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.  Reply With Quote

4. ## Re: bearing between two points

Thanks i will try it out  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured