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 (v1.1 and older) 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

15 Oct 2016, 15:24

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 !!

:)
User avatar
Exaskryz
Posts: 2882
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

15 Oct 2016, 15:44

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

15 Oct 2016, 15:56

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

15 Oct 2016, 16:32

@ 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

15 Oct 2016, 16:46

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

15 Oct 2016, 17:05

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.


:dance:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, Bing [Bot], GEOVAN, LazyVovchik and 111 guests