Champak Posted January 18, 2015 Share Posted January 18, 2015 (edited) 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? expandcollapse popupGlobal $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 January 18, 2015 by Champak Link to comment Share on other sites More sharing options...
UEZ Posted January 18, 2015 Share Posted January 18, 2015 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 More sharing options...
Champak Posted January 19, 2015 Author Share Posted January 19, 2015 Nope, that didn't fix it. It turns out the angle of approach and a few extra feet were making it seem like the bearing was off, but the original code seems to be working properly. Thanks anyway. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now