Results 1 to 2 of 2

Thread: Convert slope to bearing?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Meeko
    Posts
    135

    Convert slope to bearing?

    I calculate the slope of a line with the following equation:

    (in VB)

    slope=(y2-y1)/(x2-x1)


    I would like to convert this slope to a bearing (i.e. the angle from the North), it seems that I would get the angle with

    Atn(slope)*180/PI

    however, it seems it's not the bearing...
    and how do handle those slope with negative value?

    Thanks very much!!!

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    Hi, I'm using this one:
    VB Code:
    1. Public Sub bearing(X1, Y1, X2, Y2, peilung)
    2. 'Input X1, Y1, X2, Y2
    3. 'Output peilung (0-360)
    4. 'calculates Bearing from X1,Y1 to X2,Y2 using a 360 degree-system
    5. Const PI = 3.141592654
    6. Dim dx As Single
    7. Dim dy As Single
    8. dx = X2 - X1
    9. dy = Y2 - Y1
    10. If dy <> 0 Then
    11.         peilung = (Atn(dx / dy) * 180 / PI)
    12.         If X2 > X1 Then
    13.                 If Y2 > Y1 Then
    14.                         peilung = peilung
    15.                 Else
    16.                         peilung = 180 + peilung
    17.                 End If
    18.         Else
    19.                 If Y2 > Y1 Then
    20.                         peilung = 360 + peilung
    21.                 Else
    22.                         peilung = 180 + peilung
    23.                 End If
    24.         End If
    25. Else
    26.         If X1 > X2 Then
    27.                 peilung = 270
    28.         Else
    29.                 peilung = 90
    30.         End If
    31. End If
    32. End Sub
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

Posting Permissions

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



Click Here to Expand Forum to Full Width