Jump to content

Coordinate and bearing help


Champak
 Share

Recommended Posts

I'm trying to determine my bearings by inputting a starting and destination coordinates but my bearings seem to be off by about 6 degrees. Can I get some help, is my math wrong?

Global $startLat = "40.730222780"
Global $startLong = "-73.996576310"
Global $endLat = "40.729377235"
Global $endLong = "-73.977298738"

$PI = 4 * ATan(1)

;===Turn coordinates into degrees.
$dLat = _Radian ( Number($endLat) - Number($startLat) )
$dLong = _Radian ( Number($endLong) - Number($startLong) )

;Check which quadrant the coordinate is in and find the degrees
If $dLong > 0 Then
    $Bearing = 90 - (180 / $PI) * Atan($dLat / $dLong)
EndIf
If $dLong < 0 Then
    $Bearing = 270 - (180 / $PI) * Atan($dLat / $dLong)
EndIf

If $dLong = 0 Then
    If $dLat > 0 Then $Bearing = 0
    If $dLat < 0 Then $Bearing = 180
    If $dLat = 0 Then Return
EndIf


$Bearing = Round($bearing)
MsgBox(0,0,$Bearing)

;$READTRUECOURSE = $GPSTK.TrueCourse

#cs
_ConsoleWrite("POI: " & $NAV_POI_ARRAY[$X][0] & ", " & $NAV_POI_ARRAY[$X][1])
_ConsoleWrite("Current: " & StringTrimRight($READLAT, 4) & ", " & StringtrimLeft(StringTrimRight($READLONG, 4),1))
_ConsoleWrite("Degrees: " & $Bearing & ", Direction = " & getCompassDirection($Bearing))
_ConsoleWrite("> Range: " & $Bearing - 15 & " and " & $Bearing + 15)
_ConsoleWrite("- True Course: " & $READTRUECOURSE)
#ce

I just don't know how anyone will be able to verify their results. But if it's clear what I did wrong, please let me know.

Thanks.

Edited by Champak
Link to comment
Share on other sites

Try:

$dLat = _Radian ( Abs (Number($endLat) - Number($startLat) ) )
$dLong = _Radian ( Abs (Number($endLong) - Number($startLong) ) )

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...