Try with numbers from other quadrant also, Like dx=-3 and dy=+3 for example.
Compare two points which both lie on the diagonal with slope of -1: (Angle in degrees = -45 or 135)
ATan() goes between +90 and -90, and you seem to prefer 135 as result if possible, as far as I understand you.
Code: Select all
; point in pos y, neg x quadrant
dy := 3
dx := -3
MsgBox % Deg(ATan(dy / dx)) ; -45 math correct, but not interested
MsgBox % Deg(ATan2(dy, dx)) ; 135 want this instead
; point in neg y, pos x quadrant
dy := -3
dx := 3
MsgBox % Deg(ATan(dy / dx)) ; -45 same value, math also correct
MsgBox % Deg(ATan2(dy, dx)) ; -45
;-------------------------------------------------------------------------------
class Math { ; constant Math.PI
static PI := 4 * ATan(1)
}
Rad(Angle) { ; convert angle in degrees => angle in radians
Return, Angle * Math.PI / 180
}
Deg(Angle) { ; convert angle in radians => angle in degrees
Return, Angle * 180 / Math.PI
}
ATan2(y, x) { ; ATan() with full range
If (x > 0)
Return, ATan(y/x)
If (x < 0)
Return, ATan(y/x) + (y >= 0 ? Math.PI : -Math.PI)
; else x = 0
Return, (y > 0) ? Math.PI/2 : (y < 0) ? -Math.PI/2 : ""
}