Jump to content

Recommended Posts

Posted

Hello everyone!
For a week I have been struggling with the algorithm and without any crutches I can't do it properly, I revised a bunch of formulas and was already completely confused.
The task is as follows: the user clicks on the screen to the starting point A, then to the finish point B, and the intermediate point C. The script moves the mouse cursor in steps along this arc from point A to point B through point C, making a click in each step, including A, including B, but it is possible somewhere nearby, point C is not necessary
As I see it, the problem is that most formulas on the Internet are for a space where the point (0,0) is in the lower-left corner, as opposed to the monitor screen where it is at the top. Accordingly, the angles of points are incorrectly determined. I tried to make the Y coordinate negative, but I'm not good at geometry and I don't understand what else needs to be changed.
The main functions I have are

#include <Math.au3>
#include <Misc.au3>
#include <Date.au3>

Func GetSegmentLength($x1, $y1, $x2, $y2)
  Return Sqrt(($x2 - $x1)^2 + ($y2 - $y1)^2)
EndFunc

; Equation radius of a Circle from 3 Points
Func GetRadius($A, $B, $C)
   $m1 = ($C[1]-$A[1]) / ($C[0]-$A[0])
   $m2 = ($C[1]-$B[1]) / ($C[0]-$B[0])

   $x  = ($m1*$m2*($A[1]-$B[1])+$m2*($A[0]+$C[0])-$m1*($B[0]+$C[0])) / (2*($m2-$m1))
   $y  = (-1/$m1)*($x-($A[0]+$C[0])/2)+($A[1]+$C[1])/2

   $r  = Sqrt(($x-$A[0])^2+($y-$A[1])^2)
   Local $q[3] = [$r, $x, $y]
  Return $q
EndFunc


Func _ATan2(Const $nY, Const $nX)

    If Not IsNumber($nY) Or Not IsNumber($nX) Then Return SetError(1, 0, 0)

    Return SetError(0, 0, ATan($nY / $nX) + ((($nY <= 0) And ($nX < 0)) + (($nY > 0) And ($nX < 0)) - 2 * (($nY < 0) And ($nX < 0))) * 3.14159265358979323846)

EndFunc

Func getAngle2PointsDeg($p1_x, $p1_y, $p2_x, $p2_y)
   $pi = 4 * ATan(1)
  return ACos( ( ($p1_x * $p2_x) + ($p1_y * $p2_y) ) / (Sqrt($p1_x^2 + $p1_y^2) * sqrt($p2_x^2 + $p2_y^2)) ) * 180 / $pi
EndFunc

Func arcDraw($clockwise = 0)
   Local $A
   Local $B
   Local $C

   SplashTextOn("Arc", "Move the mouse over the 1st point and press the space bar...", 300, 180, 40, 300, 4+16, "", 14)
   While 1
      If _IsPressed("20") Then
         While _IsPressed("20") = 1
         WEnd
         Send("{SPACE} up")
         $A = MouseGetPos()
         $x1 = $A[0]
         $y1 = $A[1]
         ExitLoop
      EndIf
      Sleep(100)
   WEnd
   SplashTextOn("Arc", "Move the mouse over the 2nd point and press the space bar...", 300, 180, 40, 300, 4+16, "", 14)
   While 1
      If _IsPressed("20") Then
         While _IsPressed("20") = 1
         WEnd
         Send("{SPACE} up")
         $B = MouseGetPos()
         $x2 = $B[0]
         $y2 = $B[1]
         ExitLoop
      EndIf
      Sleep(100)
   WEnd
   SplashTextOn("Arc", "Move the mouse over the 3rd point and press the space bar...", 300, 180, 40, 300, 4+16, "", 14)
   While 1
      If _IsPressed("20") Then
         Send("{SPACE} up")
         $C = MouseGetPos()
         $x3 = $C[0]
         $y3 = $C[1]
         ExitLoop
      EndIf
      Sleep(100)
   WEnd

   $l = GetSegmentLength($A[0], $A[1], $B[0], $B[1])
   $r = GetRadius($A, $B, $C)
   $Ox = $r[1]
   $Oy = $r[2]
   $radius = $r[0]

   $pi = 4 * ATan(1)

   $AAngle = _Atan2($A[1] - $Oy, $A[0] - $Ox) * (180/$pi)
   $BAngle = _Atan2($B[1] - $Oy, $B[0] - $Ox) * (180/$pi)

   $step = $pi
   moveMouseCircle($Ox, $Oy, $radius, 0, $AAngle, $BAngle, 100, $step)
   SplashOff()
EndFunc

Func moveMouseCircle($h, $k, $radius, $direction = 0, $startangle = 0, $endangel = 360, $delay = 10, $step = 50)
    ;h = Center X
    ;k = Center Y
    ;radius in pixels
    ;direction: 0 = clockwise (default), 1 = counter-clockwise
    ;start angle in degrees (0-360): default is 0
    ;delay in milliseconds: default 10
    ;step in degrees: default 0

    $pi = 4 * ATan(1)

   $start = $startangle
   $end = $endange
    ;For $Z = 1 to 2
        For $A = $start to $end Step $step
            If $direction Then
                $X = $h - sin(_Radian($A)) * $radius
            Else
                $X = $h + sin(_Radian($A)) * $radius
            EndIf
            $Y = $k - cos(_Radian($A)) * $radius
            MouseMove ( $X, $Y, 0)
            MouseClick("left")
            Sleep($delay)
        Next
        $start = 0
        $end = $startangle
    ;Next

EndFunc

Please help with writing the script and add code for drawing an arc counterclockwise (it will be passed as an argument to the arcDraw function)

On the Internet, I also found such a function for determining angles, but I couldn't adapt it.

Spoiler
Func AnglePointToPoint($fromX, $fromY, $toX, $toY)
   $pi = 4 * ATan(1)
   $distanceX     = $toX - $fromX
   $distanceY     = -($toY - $fromY)
   $beta          = acos( abs($distanceX) / sqrt( $distanceX^2 + $distanceY^2 ) ) * 180 / $pi
   ConsoleWrite(_NowTime() & " -- dx = $distanceX$" & @CRLF)
   ConsoleWrite(_NowTime() & " -- dy = $distanceY$" & @CRLF)
   ConsoleWrite(_NowTime() & " -- beta = $beta$" & @CRLF)
   $angleResult   = 0.0

    if $distanceX > 0 Then
        if $distanceY < 0 Then
            $angleResult = $beta + 90;//right_bot
         else
            $angleResult = abs($beta - 90);//right_top
         EndIf
    else
        if $distanceY < 0 then
            $angleResult = abs($beta - 90) + 180;//left_bot
         else
            $angleResult = $beta + 270;//left_top
        EndIf
    EndIf
    return $angleResult
EndFunc

 

 

  • Moderators
Posted

What exactly are you trying to accomplish by clicking at these various points in space? There is undoubtedly an easier way to manipulate an application than through mouseclicks

 

                               =========In case you missed it, this is a Mod stepping into a thread=========

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

An application is an editor and I want to draw arc in it. The app has a photos background and there are arcs and circles on them.

Posted

Thank you for wanting to help but it doesn't matter. I need exactly what I asked for. An algorithm that will make mouse clicks on an arc.

Posted

Just subtracting the y values from your screen height should give you a usable value I believe.

If resolution is 1920x1080, instead of using y from MouseGetPos, try using (1080-y) in your formulas.

If there is a scaling set in Display Settings then ((1080*100/Scaling)-y).

  • Moderators
Posted

It does matter when a Moderator on this forum is asking for clarification. As you seem not to want to provide clear answers to my questions, this thread will be closed. Feel free to PM me with clarification if you would like it reopened. Please also review our forum rules before you post again.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

  • Moderators
Posted

Okay, I am not sure just how many times we need to post this, or how to say it any more clearly - when a Mod is clearly working in a thread, stay out of it.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...