PDA

Click to See Complete Forum and Search --> : Convert slope to bearing?


Meeko
Jan 7th, 2003, 09:43 PM
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!!!

opus
Jan 9th, 2003, 01:04 AM
Hi, I'm using this one:

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