Search the Community
Showing results for tags 'atan'.
-
This thread is about something odd i noticed with AutoIt's aTan function, that caused me a lot of time to track down. Recently i was writing a program to change GPX files, splitting each set of points into smaller directions. It works by taking the current and next point in the gpx file, calculating the angle between them, and then adding points between them every x meters until it's near enough to the second point. Lather, rinse, repeat. The problem is sometimes the angle the new points would make would go completely the wrong direction, approximately half the time. Hurm... Anyways I eventually discovered that aTan would always return a positive result. This is fine for calculating SLOPE, but for calculating ANGLE this was very annoying. I eventually came up with a work-around that works, but i was wondering if this behavior was intended or not. Example script here, will show the buggy behavior by default. Uncomment line 28 to see the expected behavior #include <GUIConstantsEx.au3> $Form1 = GUICreate("Form1", 318, 288, 192, 124) $Radio1 = GUICtrlCreateRadio("", 160, 120, 17, 17) $Label1 = GUICtrlCreateLabel("Label1", 16, 232, 316, 77) GUISetState(@SW_SHOW) Local $s, $olds, $hwnd=WinGetHandle(ControlGetHandle($Form1,"",$Radio1)) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch $pos = WinGetPos($hwnd) If @error then ContinueLoop $pos2 = MouseGetPos() $dx = $pos2[0] - $pos[0] $dy = $pos2[1] - $pos[1] $angle = ATan($dy/$dx) ;this is the fix, uncomment to see expected (desired) behavior ;~ If $dx < 0 Then $angle -= 3.14159265359 $s = "Pos 1 = "&$pos[0]&" , "&$pos[0]&" Angle= "&($angle*57.295779513)+90&@CRLF&"Pos 2 = "&$pos2[0]&" , "&$pos2[1]&@CRLF&"DX = "&$dx&" DY = "&$dy If $s <> $olds Then $olds = $s GUICtrlSetData($Label1, $s) EndIf WEnd