I'm trying to write a script which will prevent the mouse moving outside of a circle
of a set radius of pixels e.g. 100. Now it has been over 10 years since i have played with trigonometry at school...and Im not much of a programmer either - so can some one here see where i have gone wrong.

At the beginning of the function, the original mouse position is set to 0,0 (the center of the above circle),
For the large triangle: X = 120, Y = 90
therefore the angle & = Atan ( 90 / 120 )
Find the hypotenuse of the large triangle c = Sqrt( A^2 + B^2)
If C is > 100 pixels
...well you can see where i'm going with this from my code.
This script:
circle_radius_max := 200 ;hypotenuse of little triangle
F1::
MouseGetPos, center_x, center_y ;set the current location to be the center of the circle
stop := "go"
SetTimer, circle, -1
Return
F2::stop := "stop"
circle:
Loop,
{
if ( stop = "stop" )
Break
MouseGetPos, current_x, current_y
offset_x := current_x - center_x ;make the ceter of the circle (0,0) - offset_x = x of big triangle
offset_y := current_y - center_y ;(0,0) - offset_y = y of big triangle
radius_current := Sqrt((offset_x * offset_x) + (offset_y * offset_y)) ; find the radius of the big/current triangle
if ( radius_current > circle_radius_max )
{
if (offset_x < 0)
{
circle_angle := ATan(offset_x/offset_Y) ; big triangle
move_x := center_x + Sin(circle_angle) * circle_radius_max ;little triangle
move_y := center_y + Cos(circle_angle) * circle_radius_max ;little triangle
MouseMove, move_x, move_y
}
Else
{
circle_angle := ATan(offset_y/offset_x) ; big triangle
move_x := center_x + cos(circle_angle) * circle_radius_max ;little triangle
move_y := center_y + sin(circle_angle) * circle_radius_max ;little triangle
MouseMove, move_x, move_y
}
}
}
return
Produces this:
(The mouse can't enter the left-top-quarter of the circle.

Many thanks in advance.





