Jump to content

GDIPlus Arc Calculate Position


algiuxas
 Share

Recommended Posts

The angle in the picture doesn't ressemble anyway a 270° angle (a 3/4 of full rotation). If it really is 270°, no computation is needed: the blue point will be at (-90, 5).

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

The angle in the picture doesn't ressemble anyway a 270° angle (a 3/4 of full rotation). If it really is 270°, no computation is needed: the blue point will be at (-90, 5).

Thanks, but it's just an example, I need to know how to calculate it, becouse arc degree will change in my program.

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

Link to comment
Share on other sites

Like this:

#include <Array.au3>

Local $aCoord = [5, 90]
Local $Angle = 270      ; in degrees, anti-clockwise
Local $aNewCoord = _Rotate($aCoord, $Angle)
_ArrayDisplay($aNewCoord)

Func _Rotate($aXY, $deg)
    Local $rad = 2 * 3.141592653589793238 * $deg / 360
    Local $aNewXY = [$aXY[0] * Cos($rad) - $aXY[1] * Sin($rad), $aXY[0] * Sin($rad) + $aXY[1] * Cos($rad)]
    Return $aNewXY
EndFunc

 

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

Like this:

#include <Array.au3>

Local $aCoord = [5, 90]
Local $Angle = 270      ; in degrees, anti-clockwise
Local $aNewCoord = _Rotate($aCoord, $Angle)
_ArrayDisplay($aNewCoord)

Func _Rotate($aXY, $deg)
    Local $rad = 2 * 3.141592653589793238 * $deg / 360
    Local $aNewXY = [$aXY[0] * Cos($rad) - $aXY[1] * Sin($rad), $aXY[0] * Sin($rad) + $aXY[1] * Cos($rad)]
    Return $aNewXY
EndFunc

 

Thanks, but I figured out myself :D

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

Link to comment
Share on other sites

Here another way:

#include <GDIPlus.au3>
#include <Array.au3>

_GDIPlus_Startup()
Global Const $iW = 600, $iH = 400, $iSize = 4
Global Const $hGUI = GUICreate("Test", $iW, $iH)
GUISetState()
Global Const $hCanvas = _GDIPlus_GraphicsCreateFromHWND($hGUI), $hBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00)
_GDIPlus_GraphicsSetPixelOffsetMode($hCanvas, 4)
Global $aResult
_GDIPlus_GraphicsDrawLine($hCanvas, 0, $iH / 2, $iW, $iH / 2)
_GDIPlus_GraphicsDrawLine($hCanvas, $iW / 2, 0, $iW / 2, $iH)
Global $iX = 5, $iY = 90
$aResult = TransformPoint($iX, $iY, 0)
_GDIPlus_GraphicsFillRect($hCanvas, $iW / 2 + $aResult[0] - $iSize / 2, $iH / 2 + $aResult[1] - $iSize / 2, $iSize, $iSize, $hBrush)
_GDIPlus_GraphicsDrawString($hCanvas, $iX & "," & $iY, $iW / 2 + $aResult[0], $iH / 2 + $aResult[1], "Arial", 8)

$aResult = TransformPoint($iX, $iY, 270)
_GDIPlus_BrushSetSolidColor($hBrush, 0xFF0000FF)
_GDIPlus_GraphicsFillRect($hCanvas, $iW / 2 + $aResult[0] - $iSize / 2, $iH / 2 + $aResult[1] - $iSize / 2, $iSize, $iSize, $hBrush)
_GDIPlus_GraphicsDrawString($hCanvas, Round($aResult[0], 0) & "," & Round(-$aResult[1], 0), $iW / 2 + $aResult[0], $iH / 2 + $aResult[1], "Arial", 8)

_GDIPlus_GraphicsDrawString($hCanvas, "0,0", $iW / 2, $iH / 2, "Arial", 8)

_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hCanvas)
_GDIPlus_Shutdown()

Do
Until GUIGetMsg() = -3


Func TransformPoint($fX, $fY, $fAngle)
    Local Const $hMatrix = _GDIPlus_MatrixCreate(), $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddRectangle($hPath, $fX, $fY, 0.1, 0.1)
    _GDIPlus_MatrixRotate($hMatrix, -180 + $fAngle + 2 * $fX)
    _GDIPlus_PathTransform($hPath, $hMatrix)
    Local Const $aBounds = _GDIPlus_PathGetWorldBounds($hPath)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_PathDispose($hPath)
    Return $aBounds
EndFunc

 

$aResult[0] = x pos

$aResult[1] = y pos

Edited by UEZ
Extented the example

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

@UEZ

Using your example and rotating a point (5,90) around the origin 270deg clockwise, I was not getting the result (-90.5).

So I modified your example.

#include <GDIPlus.au3>

_GDIPlus_Startup()
Global Const $iW = 600, $iH = 400, $iSize = 4
Global Const $hGUI = GUICreate("Test", $iW, $iH)
GUISetState()
Global Const $hCanvas = _GDIPlus_GraphicsCreateFromHWND($hGUI), $hBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00)
_GDIPlus_GraphicsSetPixelOffsetMode($hCanvas, 4)
Global $aResult

;Arrow heads
$hPen = _GDIPlus_PenCreate(0xFF000000, 2)
$hEndCap = _GDIPlus_ArrowCapCreate(3, 6)
_GDIPlus_PenSetCustomEndCap($hPen, $hEndCap)

_GDIPlus_GraphicsDrawLine($hCanvas, 0, $iH / 2, $iW, $iH / 2, $hPen)
_GDIPlus_GraphicsDrawString($hCanvas, "X", $iW - 15, $iH / 2 - 20, "Arial", 12)

_GDIPlus_GraphicsDrawLine($hCanvas, $iW / 2, $iH, $iW / 2, 0, $hPen)
_GDIPlus_GraphicsDrawString($hCanvas, "Y", ($iW / 2) + 5, 5, "Arial", 12)

Global $iX = 5, $iY = 90
Local $aResult[2] = [$iX, -$iY] ; To have positive x-axie to the right, and positive y-axis up on the screen.
_GDIPlus_GraphicsFillRect($hCanvas, $iW / 2 + $aResult[0] - $iSize / 2, $iH / 2 + $aResult[1] - $iSize / 2, $iSize, $iSize, $hBrush)
_GDIPlus_GraphicsDrawString($hCanvas, $iX & "," & $iY, $iW / 2 + $aResult[0], $iH / 2 + $aResult[1], "Arial", 8)

$aResult = TransformPoint($iX, $iY, 270) ; Clockwise rotaton
;$aResult = TransformPoint($iX, $iY, 270 ,false) ; Anti-clockwise rotaton

_GDIPlus_BrushSetSolidColor($hBrush, 0xFF0000FF)
_GDIPlus_GraphicsFillRect($hCanvas, $iW / 2 + $aResult[0] - $iSize / 2, $iH / 2 + $aResult[1] - $iSize / 2, $iSize, $iSize, $hBrush)
_GDIPlus_GraphicsDrawString($hCanvas, Round($aResult[0], 0) & "," & Round(-$aResult[1], 0), $iW / 2 + $aResult[0], $iH / 2 + $aResult[1], "Arial", 8)

_GDIPlus_GraphicsDrawString($hCanvas, "0,0", $iW / 2, $iH / 2, "Arial", 8)

_GDIPlus_ArrowCapDispose($hEndCap)
_GDIPlus_PenDispose($hPen)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hCanvas)
_GDIPlus_Shutdown()

Do
Until GUIGetMsg() = -3

; With $bClockwise = True, point is rotated clockwise around origin.
; With $bClockwise = False, point is rotated anti-clockwise around origin.
; http://stackoverflow.com/questions/3162643/proper-trigonometry-for-rotating-a-point-around-the-origin
Func TransformPoint($fX, $fY, $fAngle, $bClockwise = True)
    Local $Pi = 4 * ATan(1)
    Local $s = Sin($fAngle * $Pi / 180);
    Local $c = Cos($fAngle * $Pi / 180)
    If $bClockwise Then
        Local $aRet[2] = [$fX * $c + $fY * $s, -(-$fX * $s + $fY * $c)] ; By default positive y-axis is down. Reverse sign of "y" coordinate to make positive y-axis to up.
    Else
        Local $aRet[2] = [$fX * $c - $fY * $s, -($fX * $s + $fY * $c)] ; Minus y coordinate makes positive y-axis to up.
    EndIf
    Return $aRet
EndFunc   ;==>TransformPoint

To check,  rotating 270deg clockwise is the same as rotating 90deg anticlockwise.

Edited by Malkey
Removed incorrect comment line.
Link to comment
Share on other sites

Here another way:

#include <GDIPlus.au3>
#include <Array.au3>

_GDIPlus_Startup()
Global Const $iW = 600, $iH = 400, $iSize = 4
Global Const $hGUI = GUICreate("Test", $iW, $iH)
GUISetState()
Global Const $hCanvas = _GDIPlus_GraphicsCreateFromHWND($hGUI), $hBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00)
_GDIPlus_GraphicsSetPixelOffsetMode($hCanvas, 4)
Global $aResult
_GDIPlus_GraphicsDrawLine($hCanvas, 0, $iH / 2, $iW, $iH / 2)
_GDIPlus_GraphicsDrawLine($hCanvas, $iW / 2, 0, $iW / 2, $iH)
Global $iX = 5, $iY = 90
$aResult = TransformPoint($iX, $iY, 0)
_GDIPlus_GraphicsFillRect($hCanvas, $iW / 2 + $aResult[0] - $iSize / 2, $iH / 2 + $aResult[1] - $iSize / 2, $iSize, $iSize, $hBrush)
_GDIPlus_GraphicsDrawString($hCanvas, $iX & "," & $iY, $iW / 2 + $aResult[0], $iH / 2 + $aResult[1], "Arial", 8)

$aResult = TransformPoint($iX, $iY, 270)
_GDIPlus_BrushSetSolidColor($hBrush, 0xFF0000FF)
_GDIPlus_GraphicsFillRect($hCanvas, $iW / 2 + $aResult[0] - $iSize / 2, $iH / 2 + $aResult[1] - $iSize / 2, $iSize, $iSize, $hBrush)
_GDIPlus_GraphicsDrawString($hCanvas, Round($aResult[0], 0) & "," & Round(-$aResult[1], 0), $iW / 2 + $aResult[0], $iH / 2 + $aResult[1], "Arial", 8)

_GDIPlus_GraphicsDrawString($hCanvas, "0,0", $iW / 2, $iH / 2, "Arial", 8)

_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hCanvas)
_GDIPlus_Shutdown()

Do
Until GUIGetMsg() = -3


Func TransformPoint($fX, $fY, $fAngle)
    Local Const $hMatrix = _GDIPlus_MatrixCreate(), $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddRectangle($hPath, $fX, $fY, 0.1, 0.1)
    _GDIPlus_MatrixRotate($hMatrix, -180 + $fAngle + 2 * $fX)
    _GDIPlus_PathTransform($hPath, $hMatrix)
    Local Const $aBounds = _GDIPlus_PathGetWorldBounds($hPath)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_PathDispose($hPath)
    Return $aBounds
EndFunc

 

$aResult[0] = x pos

$aResult[1] = y pos

Thanks, nice work! :D

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

Link to comment
Share on other sites

@algiuxas: thanks but Malkey is right. Unfortunately the rotation using the GDI+ _GDIPlus_MatrixRotate doesn't produces the proper result without any additional math.

 

It was a try to use pur GDI+ without further math but it has failed. :(

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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