|
-
Jan 7th, 2003, 10:43 PM
#1
Thread Starter
Addicted Member
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!!!
-
Jan 9th, 2003, 02:04 AM
#2
Hi, I'm using this one:
VB Code:
Public Sub bearing(X1, Y1, X2, Y2, peilung)
'Input X1, Y1, X2, Y2
'Output peilung (0-360)
'calculates Bearing from X1,Y1 to X2,Y2 using a 360 degree-system
Const PI = 3.141592654
Dim dx As Single
Dim dy As Single
dx = X2 - X1
dy = Y2 - Y1
If dy <> 0 Then
peilung = (Atn(dx / dy) * 180 / PI)
If X2 > X1 Then
If Y2 > Y1 Then
peilung = peilung
Else
peilung = 180 + peilung
End If
Else
If Y2 > Y1 Then
peilung = 360 + peilung
Else
peilung = 180 + peilung
End If
End If
Else
If X1 > X2 Then
peilung = 270
Else
peilung = 90
End If
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|