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:
1. Public Const Pi  As Double = 3.14159265358979
2. Public Const Pi2 As Double = 3.14159265358979 * 2#
3.
4. Public Const DegRad As Double = 3.14159265358979 / 180#
5. Public Const RadDeg As Double = 180# / 3.14159265358979
6.
7. Public Function ATan2(ByVal X As Double, ByVal Y As Double) As Double
8. Dim sY As Double
9. Dim sX As Double
10.     If Y < 0# Then sY = -Pi Else sY = Pi
11.     If X = 0# Then
12.         ATan2 = sY * 0.5
13.     Else
14.         If X < 0# Then sX = sY Else sX = 0#
15.         ATan2 = Atn(Y / X) + sX
16.     End If
17. '    If ATan2 < 0 Then ATan2 = ATan2 + Pi2
18. End 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.
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.  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

Click Here to Expand Forum to Full Width