winkel von der maus zur negativen x Achse berechnen

  • Hallo :D
    also ich hab jetz das problem das ich den winkel von der negativen x Achse zur mausposition berechnen will
    aba ich hab ka wie ich das anstelln soll
    also das koarinatensystem is in der mitte einer gui
    hat jemand ne idee?

  • Hi,
    ehrlich gesagt verstehe ich nicht so genau was du meinst.
    Auf dem Bildschirm gibt es keine negativen X-Werte.

    Hast du eine GUI, die in der Mitte des Bildschirmes ist und ein Koordinatensystem draufgezeichnet hat? Und dann willst du den winkel zwischen der Mausposition und der X-Achse bestimmen?

    Das musst du genauer erklären, am besten mit einem Bild oder einem Script.

  • Ich hab mal eben ein paar Funktionen dafür gebastelt, ich hoffe sie helfen dir weiter...

    Spoiler anzeigen
    [autoit]

    MsgBox(0,"",_GetLineDegreeX(5, 5, 1))

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetLineDegreeX($iX_Point, $iY_Point, $iFlag = 0)
    If Not ($iX_Point Or $iY_Point) Then Return SetError(1, 0, -1)
    Switch $iFlag
    Case 0
    Return Abs(ATan($iY_Point / $iX_Point) / (ACos(-1) / 180))
    Case 1
    Return 360 - Abs(ATan($iY_Point / $iX_Point) / (ACos(-1) / 180))
    EndSwitch
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetLineDegreeY($iX_Point, $iY_Point, $iFlag = 0)
    If Not ($iX_Point Or $iY_Point) Then Return SetError(1, 0, -1)
    Switch $iFlag
    Case 0
    Return Abs(ATan($iX_Point / $iY_Point) / (ACos(-1) / 180))
    Case 1
    Return 360 - Abs(ATan($iX_Point / $iY_Point) / (ACos(-1) / 180))
    EndSwitch
    EndFunc

    [/autoit]


    Hier noch mal überarbeitet und mit besserem Beispiel:

    Spoiler anzeigen
    [autoit]

    While Sleep(100)
    $aMousePos = MouseGetPos()
    ToolTip(Round(_GetLineDegreeX($aMousePos[0], $aMousePos[1], 1), 2) & "°", @DesktopWidth, @DesktopHeight, "", "", 4)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetLineDegreeX($iX_Point, $iY_Point, $iFlag = 0)
    If Not ($iX_Point Or $iY_Point) Then Return SetError(1, 0, 0)
    Switch $iFlag
    Case 0
    Return Abs(ATan($iY_Point / $iX_Point) / (ACos(-1) / 180))
    Case 1
    Return 180 - Abs(ATan($iY_Point / $iX_Point) / (ACos(-1) / 180))
    Case 2
    Return 360 - Abs(ATan($iY_Point / $iX_Point) / (ACos(-1) / 180))
    EndSwitch
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetLineDegreeY($iX_Point, $iY_Point, $iFlag = 0)
    If Not ($iX_Point Or $iY_Point) Then Return SetError(1, 0, 0)
    Switch $iFlag
    Case 0
    Return Abs(ATan($iX_Point / $iY_Point) / (ACos(-1) / 180))
    Case 1
    Return 180 - Abs(ATan($iX_Point / $iY_Point) / (ACos(-1) / 180))
    Case 2
    Return 360 - Abs(ATan($iX_Point / $iY_Point) / (ACos(-1) / 180))
    EndSwitch
    EndFunc

    [/autoit]
  • Ich würd das gerne nochmal erklärt bekommen...
    Wir nehmen das jetzt zufälliger Weise gerad in Mathe durch, also weiß ich, was ein arcus cosinus/sinus/tangens ist, aber das war's auch schon
    Ich benutze Scripte nicht nur, sondern verstehe sie auch mal gerne ;)

    Spoiler anzeigen

    Grundkenntnisse in: C++, JavaScript
    Sehr gute Kenntnisse: PHP, JAVA, C und näturlich AutoIt


    Klaviatur, Anhang UDF, GDI+ Mühle

    Zitat

    "Wenn einen um 20h der Pizzadienst anruft und fragt, ob man's nur vergessen hat und ob man das gleiche
    möchte wie immer -- dann sollte man sein Bestellverhalten evtl überdenken"

  • Das kann ich ;)
    Hier mal ein Ansatz:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("Form1", 501, 501, 279, 155)
    $Button1 = GUICtrlCreateButton("Button1", 240, 240, 10, 10, $WS_GROUP)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    $mouse = GUIGetCursorInfo()
    $x = $mouse[0]-250
    $y = $mouse[1]-250
    ToolTip(Round(_GetLineDegreeX($x,$y)),@DesktopWidth,@DesktopHeight,"","",4)
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

    [/autoit] [autoit][/autoit] [autoit]

    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _GetLineDegreeX($iX_Point, $iY_Point, $iFlag = 0)
    If Not ($iX_Point Or $iY_Point) Then Return SetError(1, 0, 0)
    Switch $iFlag
    Case 0
    Return Abs(ATan($iY_Point / $iX_Point) / (ACos(-1)/ 180 ))
    Case 1
    Return 180 - Abs(ATan($iY_Point / $iX_Point) / (ACos(-1) / 180))
    Case 2
    Return 360 - Abs(ATan($iY_Point / $iX_Point) / (ACos(-1) / 180))
    EndSwitch
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetLineDegreeY($iX_Point, $iY_Point, $iFlag = 0)
    If Not ($iX_Point Or $iY_Point) Then Return SetError(1, 0, 0)
    Switch $iFlag
    Case 0
    MsgBox(0,"",ATan($iX_Point / $iY_Point))
    Return Abs(ATan($iX_Point / $iY_Point) / (ACos(-1) / 180))
    Case 1
    Return 180 - Abs(ATan($iX_Point / $iY_Point) / (ACos(-1) / 180))
    Case 2
    Return 360 - Abs(ATan($iX_Point / $iY_Point) / (ACos(-1) / 180))
    EndSwitch
    EndFunc

    [/autoit]

    Edit: Der Button ist der Mittelpunkt...

    Spoiler anzeigen

    Grundkenntnisse in: C++, JavaScript
    Sehr gute Kenntnisse: PHP, JAVA, C und näturlich AutoIt


    Klaviatur, Anhang UDF, GDI+ Mühle

    Zitat

    "Wenn einen um 20h der Pizzadienst anruft und fragt, ob man's nur vergessen hat und ob man das gleiche
    möchte wie immer -- dann sollte man sein Bestellverhalten evtl überdenken"

  • Hier mal mein Ansatz 8) .

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("Degree", 400, 400)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics(400, 400, $hGraphic)
    $hBitmap_BG = _GDIPlus_BitmapCreateFromGraphics(400, 400, $hGraphic)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    $hBuffer_BG = _GDIPlus_ImageGetGraphicsContext($hBitmap_BG)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer_BG, 2)

    [/autoit] [autoit][/autoit] [autoit]

    $hPenRed = _GDIPlus_PenCreate(0xFFFF0000, 2)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsClear($hBuffer_BG, 0xFFFFFFFF)
    _GDIPlus_GraphicsDrawLine($hBuffer_BG, 0, 200, 400, 200)
    _GDIPlus_GraphicsDrawLine($hBuffer_BG, 200, 0, 200, 400)
    _GDIPlus_GraphicsFillEllipse($hBuffer_BG, 198, 198, 4, 4)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    OnAutoItExitRegister("_Exit")

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(15)
    $aMousePos = GUIGetCursorInfo($hWnd)
    $iAngle = Round(_GetLineDegreeX($aMousePos[0] - 200, $aMousePos[1] - 200), 2)
    If $aMousePos[0] >= 200 Then $iAngle += 180
    If $aMousePos[1] >= 200 And $aMousePos[0] <= 200 Then $iAngle += 360
    _GDIPlus_GraphicsDrawImageRect($hBuffer, $hBitmap_BG, 0, 0, 400, 400)
    _GDIPlus_GraphicsDrawLine($hBuffer, $aMousePos[0], $aMousePos[1], 200, 200, $hPenRed)
    _GDIPlus_GraphicsDrawPie($hBuffer, 150, 150, 100, 100, -180, $iAngle, $hPenRed)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 400, 400)
    ToolTip($iAngle & "°")
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetLineDegreeX($iX_Point, $iY_Point, $iFlag = 0)
    If Not ($iX_Point Or $iY_Point) Then Return SetError(1, 0, 0)
    Switch $iFlag
    Case 0
    Return ATan($iY_Point / $iX_Point) / (ACos(-1) / 180)
    Case 1
    Return 180 - Abs(ATan($iY_Point / $iX_Point) / (ACos(-1) / 180))
    Case 2
    Return 360 - Abs(ATan($iY_Point / $iX_Point) / (ACos(-1) / 180))
    EndSwitch
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetLineDegreeY($iX_Point, $iY_Point, $iFlag = 0)
    If Not ($iX_Point Or $iY_Point) Then Return SetError(1, 0, 0)
    Switch $iFlag
    Case 0
    Return Abs(ATan($iX_Point / $iY_Point) / (ACos(-1) / 180))
    Case 1
    Return 180 - Abs(ATan($iX_Point / $iY_Point) / (ACos(-1) / 180))
    Case 2
    Return 360 - Abs(ATan($iX_Point / $iY_Point) / (ACos(-1) / 180))
    EndSwitch
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_GraphicsDispose($hBuffer_BG)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap_BG)
    _GDIPlus_PenDispose($hPenRed)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

    [/autoit]
  • Ok, ich frag nochmal, weil meine Frage anscheinend in der Shoutbox untergegangen ist...
    Wieso muss man den Arcus Tangens durch Arcus Cosinus -1 durch 180 rechnen?

    P.S.: Super sript Name :thumbup:

    Spoiler anzeigen

    Grundkenntnisse in: C++, JavaScript
    Sehr gute Kenntnisse: PHP, JAVA, C und näturlich AutoIt


    Klaviatur, Anhang UDF, GDI+ Mühle

    Zitat

    "Wenn einen um 20h der Pizzadienst anruft und fragt, ob man's nur vergessen hat und ob man das gleiche
    möchte wie immer -- dann sollte man sein Bestellverhalten evtl überdenken"

  • ah, danke ^^
    Ich hab da schon überall nach gesucht...

    Edit: Lol, ich wusste gar nicht, dass ACos(-1) = π ist 8|

    Spoiler anzeigen

    Grundkenntnisse in: C++, JavaScript
    Sehr gute Kenntnisse: PHP, JAVA, C und näturlich AutoIt


    Klaviatur, Anhang UDF, GDI+ Mühle

    Zitat

    "Wenn einen um 20h der Pizzadienst anruft und fragt, ob man's nur vergessen hat und ob man das gleiche
    möchte wie immer -- dann sollte man sein Bestellverhalten evtl überdenken"

  • Interessant...
    Dann ist ja ATan(1)*4 = ACos(-1) (wow, ich 2 Sachen gleichsetzten ^^)

    Spoiler anzeigen

    Grundkenntnisse in: C++, JavaScript
    Sehr gute Kenntnisse: PHP, JAVA, C und näturlich AutoIt


    Klaviatur, Anhang UDF, GDI+ Mühle

    Zitat

    "Wenn einen um 20h der Pizzadienst anruft und fragt, ob man's nur vergessen hat und ob man das gleiche
    möchte wie immer -- dann sollte man sein Bestellverhalten evtl überdenken"

  • Hier ein "Fast Hack"!

    Vielleicht bringt's ja was:

    Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>
    Opt("GUIOnEventMode", 1)
    Opt("MouseCoordMode", 2)
    $width = 600
    $height = $width
    $w05 = $width / 2
    $h05 = $height / 2
    $180_div_pi = 180 / ACos(-1)
    Local $mx = $w05, $my = $h05
    $r = 100
    $r2 = $r / 2
    $angle = 0
    $hGUI = GUICreate("GDI+ Trigonometrie by UEZ 2010", $width, $height)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphics)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
    _GDIPlus_GraphicsClear($hBuffer, 0xFFF0F0F0)
    $hPen1 = _GDIPlus_PenCreate(0xFF0000A0, 2)
    $hPen2 = _GDIPlus_PenCreate(0xA0000000, 1)
    $hBrush1 = _GDIPlus_BrushCreateSolid(0x8000A000)
    $hBrush2 = _GDIPlus_BrushCreateSolid(0x80A00000)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetOnEvent(-3,"_Exit")

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(30)
    _GDIPlus_GraphicsClear($hBuffer, 0xA0F0F0F0)
    _GDIPlus_GraphicsDrawLine($hBuffer, 0, $h05, $width, $h05, $hPen2)
    _GDIPlus_GraphicsDrawLine($hBuffer, $w05, 0, $w05, $height, $hPen2)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDrawString($hBuffer, "X", $width - 15, $h05)
    _GDIPlus_GraphicsDrawString($hBuffer, "Y", $w05 - 15, 0)
    _GDIPlus_GraphicsDrawString($hBuffer, "-X", 2, $h05)
    _GDIPlus_GraphicsDrawString($hBuffer, "-Y", $w05 - 20, $height - 17)

    [/autoit] [autoit][/autoit] [autoit]

    $mpos = MouseGetPos()
    $mwx = $mpos[0] - $w05
    $mwy = $h05 - $mpos[1]
    $pd = Pixel_Distance($w05, $h05, $mpos[0], $mpos[1])
    If $pd > 50 And $pd < $w05 - 10 Then
    $angle = -ATan($mwy / $mwx) * $180_div_pi
    If $mwx < 0 Then
    $angle = -180 + $angle
    ElseIf $mwx >= 0 And $mwy < 0 Then
    $angle = -360 + $angle
    EndIf
    _GDIPlus_GraphicsDrawString($hBuffer, StringFormat("%.2f", Abs($angle)) & "°", $mpos[0], $h05)
    _GDIPlus_GraphicsFillPie($hBuffer, $w05 - $r2, $h05 - $r2, $r, $r, 0, $angle, $hBrush1)
    ;~ _GDIPlus_GraphicsFillPie($hBuffer, $w05 - $r2, $h05 - $r2, $r, $r, -180, $angle, $hBrush2)
    _GDIPlus_GraphicsDrawLine($hBuffer, $width - $mpos[0], $height - $mpos[1], $mpos[0], $mpos[1], $hPen1)
    $mx = $mpos[0]
    $my = $mpos[1]
    Else
    _GDIPlus_GraphicsDrawString($hBuffer, StringFormat("%.2f", Abs($angle)) & "°", $mx, $h05)
    _GDIPlus_GraphicsFillPie($hBuffer, $w05 - $r2, $h05 - $r2, $r, $r, 0, $angle, $hBrush1)
    ;~ _GDIPlus_GraphicsFillPie($hBuffer, $w05 - $r2, $h05 - $r2, $r, $r, -180, $angle, $hBrush2)
    _GDIPlus_GraphicsDrawLine($hBuffer, $width - $mx, $height - $my, $mx, $my, $hPen1)
    EndIf
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func Pixel_Distance($x1, $y1, $x2, $y2) ;Pythagoras theorem
    Local $a, $b, $c
    If $x2 = $x1 And $y2 = $y1 Then
    Return 0
    Else
    $a = $y2 - $y1
    $b = $x2 - $x1
    $c = Sqrt($a * $a + $b * $b)
    Return $c
    EndIf
    EndFunc ;==>Pixel_Distance

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    _GDIPlus_BrushDispose($hBrush1)
    _GDIPlus_BrushDispose($hBrush2)
    _GDIPlus_PenDispose($hPen1)
    _GDIPlus_PenDispose($hPen2)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

    [/autoit]

    Gruß,
    UEZ