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
Results 1 to 4 of 4

Thread: bearing between two points

  1. #1

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    38

    bearing between two points

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

  2. #2

  3. #3
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: bearing between two points

    Quote 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.
    Last edited by jeroen79; Oct 7th, 2007 at 03:31 PM.

  4. #4

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    38

    Re: bearing between two points

    Thanks i will try it out

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