Jump to content

Position to angles(degrees)


algiuxas
 Share

Recommended Posts

We do not spoon feed users here, we help to solve problems if you've run into errors.
What have you tried so far?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

When you search the web you will find a lot of hits. You just need to translate them to AutoIt.
Example

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

To add to what Water just said you also should learn to ask sensible questions. In 2D (since you mentionned x,y only) determination of angle requires knowing an origin and two points or two lines. From this point of view, your question as it is doesn't make any sense.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Something like this?

 

[example.au3]

#include-once
#include <Array.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Math.au3>
#include <MyMath.au3>

#include <WindowsConstants.au3>
#include <GUIConstants.au3>

;~ #include <APIMiscConstants.au3>
#include <WinAPIMisc.au3>

Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)
Opt("MustDeclareVars", 1)

OnAutoItExitRegister("_on_exit")

Global $hGui
Global $hGraphic, $hPen, $hBitmap, $hBackbuffer
Global $g_iMouseX, $g_iMouseY, $iAngle = 0

Global $aBoard[10] = [10, 10, 800, 600]
$aBoard[4] = $aBoard[0]
$aBoard[5] = $aBoard[1]
$aBoard[6] = $aBoard[0] + $aBoard[2]
$aBoard[7] = $aBoard[1] + $aBoard[3]
$aBoard[8] = $aBoard[2] / 2
$aBoard[9] = $aBoard[3] / 2

Global $iUpdate = 15

$hGui = GUICreate("Titulo", 820, 620)
GUISetOnEvent($GUI_EVENT_CLOSE, "_quit")


_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($aBoard[2], $aBoard[3], $hGraphic)
$hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

$hPen = _GDIPlus_PenCreate()
_GDIPlus_GraphicsClear($hBackbuffer)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)

GUISetState(@SW_SHOW, $hGui)

GUIRegisterMsg($WM_MOUSEMOVE, "WM_MOUSEMOVE")

AdlibRegister("_update", $iUpdate)

While Sleep(10)

WEnd

Func _update()
    _GDIPlus_GraphicsClear($hBackbuffer, 0xF0FFFFFF)
    _box($hBackbuffer, 0, 0, 10, 10)
    _GDIPlus_GraphicsDrawLine($hBackbuffer, $aBoard[8], $aBoard[9], $g_iMouseX, $g_iMouseY, $hPen)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, $aBoard[0], $aBoard[1], $aBoard[2], $aBoard[3])
EndFunc   ;==>_update

Func _on_exit()
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>_on_exit

Func _quit()
    Exit
EndFunc   ;==>_quit

Func _box($hToGraphic, $xx, $yy, $ll, $aa, $color = 0xFF000000)
    Local $aBox[5][2]
    $aBox[0][0] = 4
    $aBox[1][0] = $xx
    $aBox[1][1] = $yy
    $aBox[2][0] = $xx + $ll - 1
    $aBox[2][1] = $yy
    $aBox[3][0] = $xx + $ll - 1
    $aBox[3][1] = $yy + $aa - 1
    $aBox[4][0] = $xx
    $aBox[4][1] = $yy + $aa - 1
    If $color Then
        _GDIPlus_PenSetColor($hPen, $color)
        _GDIPlus_GraphicsDrawPolygon($hToGraphic, $aBox, $hPen)
    Else
        _GDIPlus_GraphicsDrawPolygon($hToGraphic, $aBox)
    EndIf
EndFunc   ;==>_box


Func calcula()
    Local $iDistancia = __GetDistance($aBoard[8], $aBoard[9], $g_iMouseX, $g_iMouseY)
    ConsoleWrite("$iDistancia[ " & $iDistancia & " ]" & @LF)
    Local $iAngulo = __GetAngle($aBoard[8], $aBoard[9], $g_iMouseX, $g_iMouseY)
    ConsoleWrite("$iAngulo[ " & _Degree($iAngulo) & " ]" & @LF)
EndFunc   ;==>calcula

Func WM_MOUSEMOVE($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Switch BitAND($wParam, 0x0000FFFF)
        Case 0
            $g_iMouseX = BitAND($lParam, 0x0000FFFF)
            $g_iMouseY = BitShift($lParam, 16)
            calcula()
        Case 1
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_MOUSEMOVE

[MyMath.au3]

Global $__iDX, $__iDY, $__iDZ, $__iDA
;~ Global Const $PI = 3.1415926535897932384626433832795
Global Const $PI = 3.141592653589793
Global Const $PI2 = $PI / 2
Global Const $2PI = $PI * 2
Global Const $5PI = $PI * 1.5
Global Const $fDegToRad = $PI / 180

Func __GetDiagonal($__iDX, $__iDY)
    Return Sqrt($__iDX ^ 2 + $__iDY ^ 2)
EndFunc   ;==>_diagonal

Func __GetDistance($iX1 = 0, $iY1 = 0, $iX2 = 0, $iY2 = 0)
;~  ConsoleWrite("__GetDistance( $iX1=" & $iX1 & ", $iY1=" & $iY1 & ", $iX2=" & $iX2 & ", $iY2=" & $iY2 & " )" & @LF)
    $__iDX = Abs($iX2 - $iX1)
    $__iDY = Abs($iY2 - $iY1)

    If Not $__iDX And Not $__iDY Then Return 0
    If Not $__iDX Then Return $__iDY
    If Not $__iDY Then Return $__iDX
    Return Sqrt($__iDX ^ 2 + $__iDY ^ 2)
EndFunc   ;==>__GetDistance


; soma 2 angulos
; mode = 0 => angulos em RAD
; mode = 1 => angulus em graus
Func __SumAngles($iA1 = 0, $iA2 = 0, $iMode = 0)
    Switch $iMode
        Case 0
            $__iDA = $iA1 + $iA2
            While $__iDA >= $2PI
                $__iDA -= $2PI
            WEnd

            While $__iDA < 0
                $__iDA += $2PI
            WEnd
        Case Else
            $__iDA = $iA1 + $iA2
            While $__iDA >= 360
                $__iDA -= 360
            WEnd

            While $__iDA < 0
                $__iDA += 360
            WEnd
    EndSwitch
    Return $__iDA
EndFunc   ;==>__SumAngles

Func __GetAngle($iX1 = 0, $iY1 = 0, $iX2 = 0, $iY2 = 0)
;~  ConsoleWrite("__GetAngle( $iX1=" & $iX1 & ", $iY1=" & $iY1 & ", $iX2=" & $iX2 & ", $iY2=" & $iY2 & " )" & @LF)
    If $iX1 = $iX2 Then
        If $iY1 = $iY2 Then
            Return SetError(1, 0, -1)
        Else
            If $iY1 > $iY2 Then
                Return $PI / 2
            Else
                Return $5PI
            EndIf
        EndIf
    Else
        $__iDX = $iX2 - $iX1
        $__iDY = $iY2 - $iY1
        If $iX1 > $iX2 Then
            If $iY1 = $iY2 Then
                Return $PI
            Else
                If $iY1 > $iY2 Then
                    Return $PI2 + ATan($__iDX / $__iDY)
                Else
                    Return $5PI + ATan($__iDX / $__iDY)
                EndIf
            EndIf
        Else
            If $iY1 = $iY2 Then
                Return 0
            Else
                If $iY1 > $iY2 Then
                    Return $PI2 + ATan($__iDX / $__iDY)
                Else
                    Return $5PI + ATan($__iDX / $__iDY)
                EndIf
            EndIf
        EndIf
    EndIf
EndFunc   ;==>__GetAngle

 

Edited by Luigi

Visit my repository

Link to comment
Share on other sites

Something like this?

 

Global $__iDX, $__iDY, $__iDZ, $__iDA
;~ Global Const $PI = 3.1415926535897932384626433832795
Global Const $PI = 3.141592653589793
Global Const $PI2 = $PI / 2
Global Const $2PI = $PI * 2
Global Const $5PI = $PI * 1.5
Global Const $fDegToRad = $PI / 180

Func __GetDiagonal($__iDX, $__iDY)
    Return Sqrt($__iDX ^ 2 + $__iDY ^ 2)
EndFunc   ;==>_diagonal

Func __GetDistance($iX1 = 0, $iY1 = 0, $iX2 = 0, $iY2 = 0)
;~  ConsoleWrite("__GetDistance( $iX1=" & $iX1 & ", $iY1=" & $iY1 & ", $iX2=" & $iX2 & ", $iY2=" & $iY2 & " )" & @LF)
    $__iDX = Abs($iX2 - $iX1)
    $__iDY = Abs($iY2 - $iY1)

    If Not $__iDX And Not $__iDY Then Return 0
    If Not $__iDX Then Return $__iDY
    If Not $__iDY Then Return $__iDX
    Return Sqrt($__iDX ^ 2 + $__iDY ^ 2)
EndFunc   ;==>__GetDistance


; soma 2 angulos
; mode = 0 => angulos em RAD
; mode = 1 => angulus em graus
Func __SumAngles($iA1 = 0, $iA2 = 0, $iMode = 0)
    Switch $iMode
        Case 0
            $__iDA = $iA1 + $iA2
            While $__iDA >= $2PI
                $__iDA -= $2PI
            WEnd

            While $__iDA < 0
                $__iDA += $2PI
            WEnd
        Case Else
            $__iDA = $iA1 + $iA2
            While $__iDA >= 360
                $__iDA -= 360
            WEnd

            While $__iDA < 0
                $__iDA += 360
            WEnd
    EndSwitch
    Return $__iDA
EndFunc   ;==>__SumAngles

Func __GetAngle($iX1 = 0, $iY1 = 0, $iX2 = 0, $iY2 = 0)
;~  ConsoleWrite("__GetAngle( $iX1=" & $iX1 & ", $iY1=" & $iY1 & ", $iX2=" & $iX2 & ", $iY2=" & $iY2 & " )" & @LF)
    If $iX1 = $iX2 Then
        If $iY1 = $iY2 Then
            Return SetError(1, 0, -1)
        Else
            If $iY1 > $iY2 Then
                Return $PI / 2
            Else
                Return $5PI
            EndIf
        EndIf
    Else
        $__iDX = $iX2 - $iX1
        $__iDY = $iY2 - $iY1
        If $iX1 > $iX2 Then
            If $iY1 = $iY2 Then
                Return $PI
            Else
                If $iY1 > $iY2 Then
                    Return $PI2 + ATan($__iDX / $__iDY)
                Else
                    Return $5PI + ATan($__iDX / $__iDY)
                EndIf
            EndIf
        Else
            If $iY1 = $iY2 Then
                Return 0
            Else
                If $iY1 > $iY2 Then
                    Return $PI2 + ATan($__iDX / $__iDY)
                Else
                    Return $5PI + ATan($__iDX / $__iDY)
                EndIf
            EndIf
        EndIf
    EndIf
EndFunc   ;==>__GetAngle

 

Thank you, it works perfectly!

After switching years ago to Linux, sadly I don't use AutoIt anymore.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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