## Measure the angle between horizontal x axis and a line joining mouse pointer position and center of the monitor Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Jameso_0
Posts: 52
Joined: 14 Oct 2015, 22:37

### Measure the angle between horizontal x axis and a line joining mouse pointer position and center of the monitor

center of my screen : point O
mouse pointer position a( x,y)

I need to measure the angle between line aO and horizontal x axis

image http://i.imgur.com/nkqqqHm.png

i used ATan method but failed , I don't know how to do this. Is there a way I can measure this angle ?

Please Help !!

Exaskryz
Posts: 2877
Joined: 17 Oct 2015, 20:28

### Re: Measure the angle between horizontal x axis and a line joining mouse pointer position and center of the monitor

What was your actual code though?

Code: Select all

``````^2::
; tan(θ) = opp/adj
CoordMode, Mouse, Screen
MouseGetPos, x, y
opp:=A_ScreenHeight/2-y
adj:=x-A_ScreenWidth/2
; the subtraction is done opposite to match the traditional coordinates where Quadrant I is positive distances in X and Y, Quadrant II is positive in Y and negative in X, Quadrant III is negative in both, and Quadrant IV is positive in X and negative in Y
pi:=4*ATan(1) ; referenced documentation on built-in functions
angle:=ATan(opp/adj)*180/pi "°"

MsgBox your angle is %angle%
return
``````
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

### Re: Measure the angle between horizontal x axis and a line joining mouse pointer position and center of the monitor

Code: Select all

``````CoordMode, Mouse, Screen
ScreenCentX := A_ScreenWidth // 2
ScreenCentY := A_ScreenHeight // 2
Pi := 4 * ATan(1)
Conversion := -180 / Pi  ; Radians to deg.
SetTimer, UpdateTooltip, 50
return

UpdateTooltip:
MouseGetPos, MouseX, MouseY
Angle := DllCall("msvcrt.dll\atan2", "Double", MouseY-ScreenCentY, "Double", MouseX-ScreenCentX, "CDECL Double") * Conversion
ToolTip, % Angle
return

^Esc::ExitApp  ; Ctrl+Esc exit script``````
Also see: Compass - Measure angles and scale distances with your mouse
Jameso_0
Posts: 52
Joined: 14 Oct 2015, 22:37

### Re: Measure the angle between horizontal x axis and a line joining mouse pointer position and center of the monitor

@ Exaskryz ; I used primitive school geometry. I calculated the slope of the line and used ATan method to determine the angle. I deleted the script

I am still not getting right angle with the help of given script, it works well when the pointer is in first quadrant. when I move my mouse in the second quadrant the value of the angle is negative and angle is measured with respect to negative x axis, for ex. the angle should be 170° but instead it is -10°,

I want value in 360°, ex the angle is 270 °

@ kon

Your scripts works well when my mouse pointer is in 1st or 2nd Quadrant , but when my is in 3rd or 4th quadrant , the value of the angle is negative and angle is measured clockwise , 350 ° becomes -10 °

need help !
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

### Re: Measure the angle between horizontal x axis and a line joining mouse pointer position and center of the monitor  Topic is solved

Jameso_0 wrote:I want value in 360°, ex the angle is 270 °
Oh, ok.
Jameso_0 wrote:Your scripts works well when my mouse pointer is in 1st or 2nd Quadrant , but when my is in 3rd or 4th quadrant , the value of the angle is negative and angle is measured clockwise , 350 ° becomes -10 °

need help !
If the value is negative, do Angle += 360:

Code: Select all

``````CoordMode, Mouse, Screen
ScreenCentX := A_ScreenWidth // 2
ScreenCentY := A_ScreenHeight // 2
Pi := 4 * ATan(1)
Conversion := -180 / Pi  ; Radians to deg.
SetTimer, UpdateTooltip, 50
return

UpdateTooltip:
MouseGetPos, MouseX, MouseY
Angle := DllCall("msvcrt.dll\atan2", "Double", MouseY-ScreenCentY, "Double", MouseX-ScreenCentX, "CDECL Double") * Conversion
if (Angle < 0)
Angle += 360
ToolTip, % Angle
return

^Esc::ExitApp  ; Ctrl+Esc exit script``````
Jameso_0
Posts: 52
Joined: 14 Oct 2015, 22:37

### Re: Measure the angle between horizontal x axis and a line joining mouse pointer position and center of the monitor

Thank You very much Kon and Exaskryz you guys saved me a lot of time , it means a lot to me. Now I feel fine

No words , saved me a lot of time. Thank you guys as usual you are always helpful. I totally appreciate your help.

Return to “Ask for Help”

### Who is online

Users browsing this forum: crocodile, DrReflex, jNizM, PepeLapiu, QyouLimYT, Rohwedder and 56 guests