cili1 Posted May 23, 2009 Share Posted May 23, 2009 Hello!I'm making a program that calculates the angle to a position on the X/Y axis.The problem is that as soon as I input a negative position (for example. -2, -2) it resets at 180° and "starts all over again".I want to be able to get the angles above 180° as I illustrate in the picture below.The blue text shows what values it shows at the moment.Green text is what I want it to show.#include <GUIConstants.au3> #include <Math.au3> $Form1 = GUICreate("Angle?", 180, 60, 500, 400) GUISetState(@SW_SHOW) GUICtrlCreateLabel("Y", 5, 5, 15, 20) GUICtrlCreateLabel("X", 5, 30, 15, 20) $GUI_a = GUICtrlCreateInput("", 20, 5, 150, 20) $GUI_c = GUICtrlCreateInput("", 20, 30, 150, 20) HotKeySet("{F1}", "Calc") HotKeySet("{ESC}", "Terminate") While 1 WEnd Func Calc() $a = GUICtrlRead($GUI_a) $c = GUICtrlRead($GUI_c) $b = Sqrt($a*$a+$c*$c) $calc1 = $b*$b + $c*$c $calc2 = -2*$b*$c $calc3 = $a*$a - $calc1 $calc4 = $calc3/$calc2 $cos = ACos($calc4) $test = Round(_Degree($cos), 2) MsgBox(0, "", $test & "%") EndFunc Func Terminate() Exit 0 EndFunc Link to comment Share on other sites More sharing options...
Yashied Posted May 23, 2009 Share Posted May 23, 2009 (edited) Returns the angle relative the center of your screen. MsgBox(0, '', _Angle(@DesktopWidth / 2 + 100, @DesktopHeight / 2 + 100)) Func _Angle($X, $Y) Local $CX = @DesktopWidth / 2, $CY = @DesktopHeight / 2 If ($CX = $X) And ($CY = $Y) Then Return SetError(1, 0, -1) EndIf Local $Grad = ($Y <= $CY) * 180 - ATan(($CX - $X) / ($CY - $Y)) * 180 / 3.1415926535897932384626 + 90 If $Grad = 360 Then $Grad = 0 EndIf Return $Grad EndFunc ;==>_Angle Edited May 23, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
cili1 Posted May 23, 2009 Author Share Posted May 23, 2009 Returns the angle relative the center of your screen.Thank you!Problem solved. 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