# GDIPlus Arc Calculate Position

## Recommended Posts

Hello, I'm weak at mathematic, I need help, I need to find blue point, I know only red points positions, and arc degree:
ArcAutoIt3ForumsHelp.bmp
Thank you very much!

ArcAutoIt3ForumsHelp.bmp

Edited by algiuxas

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

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
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)

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

##### 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
Return \$aNewXY
EndFunc```

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
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)

##### 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
Return \$aNewXY
EndFunc```

Thanks, but I figured out myself

##### 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_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

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

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

```#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

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

##### 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_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!

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

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

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...