# A little trigonometry help

## Recommended Posts

Hi there

I am trying to do a very stupid script... I want the line to do a full circle.

The problem is I actually don't know trigonometry... so I'm trying to put together informations I found, guesses and luck XD

Though I have to say I am starting to understand the x and y part...

Any kind of help would be greatly appreciated

btw... this skips a quarter of a circle... I think

```#include <GDIPlus.au3>
\$pi = 3.14159265358979
\$GUI = GUICreate("",600,600)
GUISetState()
_GDIPlus_Startup()
\$hGraphics = _GDIPlus_GraphicsCreateFromHWND(\$GUI)

_GDIPlus_GraphicsFillRect(\$hGraphics,300,300,2,2)

For \$i = 0 to 360
_GDIPlus_GraphicsClear(\$hGraphics,0xFFFFFFFF)
\$x = tan(\$pi/4)
\$y = Tan(\$i * \$degToRad)  ;tangent of 90°
If Mod(\$i, 90)=Round(Mod(\$i, 90),0) And \$y>0 Then \$x*=(-1)
If Mod(\$i, 90)=Round(Mod(\$i, 90),0) AND \$x<0 Then \$y*=(-1)
If Mod(\$i, 180)=Round(Mod(\$i, 180), 0) Then
\$x*=(-1)
\$y=(\$y+1)*(-1)
EndIf
_GDIPlus_GraphicsDrawLine(\$hGraphics,300,300,300+\$x*20,300+\$y*20)
_GDIPlus_GraphicsDrawString(\$hGraphics, \$i&"°"&@CRLF&Round(\$x,1)&@CRLF&round(\$y,1),0,0)
Sleep(50)
Next

while 1
Switch GUIGetMsg()
Case -3
_GDIPlus_Shutdown()
Exit
EndSwitch
WEnd```

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

##### Share on other sites

I made this function awhile back. Input the starting X, Y ,angle (degrees), and length, output is ending X,Y.

```Func Angle(\$x1, \$y1, \$Ang, \$Length)
Local \$Return[2]
\$Return[0] = \$x1 + (\$Length * Cos(\$Ang / 180 * 3.14159265358979))
\$Return[1] = \$y1 - (\$Length * Sin(\$Ang / 180 * 3.14159265358979))
Return \$Return
EndFunc;==>Angle```

Original post:

#463161

Edited by weaponx

##### Share on other sites

Thanks weaponx. Nice example

Just to understand... Were I completely wrong assuming I had to use Tan() or is there a way to do this ?

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

##### Share on other sites

Hi there

I am trying to do a very stupid script... I want the line to do a full circle.

The problem is I actually don't know trigonometry... so I'm trying to put together informations I found, guesses and luck XD

Though I have to say I am starting to understand the x and y part...

Any kind of help would be greatly appreciated

btw... this skips a quarter of a circle... I think

```#include <GDIPlus.au3>
\$pi = 3.14159265358979
\$GUI = GUICreate("",600,600)
GUISetState()
_GDIPlus_Startup()
\$hGraphics = _GDIPlus_GraphicsCreateFromHWND(\$GUI)

_GDIPlus_GraphicsFillRect(\$hGraphics,300,300,2,2)

For \$i = 0 to 360
_GDIPlus_GraphicsClear(\$hGraphics,0xFFFFFFFF)
\$x = tan(\$pi/4)
\$y = Tan(\$i * \$degToRad)  ;tangent of 90°
If Mod(\$i, 90)=Round(Mod(\$i, 90),0) And \$y>0 Then \$x*=(-1)
If Mod(\$i, 90)=Round(Mod(\$i, 90),0) AND \$x<0 Then \$y*=(-1)
If Mod(\$i, 180)=Round(Mod(\$i, 180), 0) Then
\$x*=(-1)
\$y=(\$y+1)*(-1)
EndIf
_GDIPlus_GraphicsDrawLine(\$hGraphics,300,300,300+\$x*20,300+\$y*20)
_GDIPlus_GraphicsDrawString(\$hGraphics, \$i&"°"&@CRLF&Round(\$x,1)&@CRLF&round(\$y,1),0,0)
Sleep(50)
Next

while 1
Switch GUIGetMsg()
Case -3
_GDIPlus_Shutdown()
Exit
EndSwitch
WEnd```
You have made it much more difficult than it really is.

```#include <GDIPlus.au3>
\$pi = 3.14159265358979
\$GUI = GUICreate("",600,600)
GUISetState()
_GDIPlus_Startup()
\$hGraphics = _GDIPlus_GraphicsCreateFromHWND(\$GUI)

_GDIPlus_GraphicsFillRect(\$hGraphics,300,300,2,2)
For \$i = 0 to 360
_GDIPlus_GraphicsClear(\$hGraphics,0xFFFFFFFF)
;\$x = tan(\$pi/4);this is  1
;\$y = Tan(\$i * \$degToRad) ;tangent of 90°
;If Mod(\$i, 90)=Round(Mod(\$i, 90),0) And \$y>0 Then \$x*=(-1)
; If Mod(\$i, 90)=Round(Mod(\$i, 90),0) AND \$x<0 Then \$y*=(-1)
; If Mod(\$i, 180)=Round(Mod(\$i, 180), 0) Then
;;   \$x*=(-1)
;   \$y=(\$y+1)*(-1)
;EndIf
_GDIPlus_GraphicsDrawLine(\$hGraphics,300,300,300+\$x*20,300+\$y*20)
_GDIPlus_GraphicsDrawString(\$hGraphics, \$i&"°"&@CRLF&Round(\$x,1)&@CRLF&round(\$y,1),0,0)
Sleep(50)
Next

while 1
Switch GUIGetMsg()
Case -3
_GDIPlus_Shutdown()
Exit
EndSwitch
WEnd```

You don't need to worry about the sign because that is automatically taken care of in the sin and cos functions. EG cos 45 deg is 0.707 approx and cos 135 deg is -0.707

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

##### Share on other sites

Were I completely wrong assuming I had to use Tan() or is there a way to do this ?

The standard method is using Cos and Sin. But, if you know that Tan = Sin / Cos then you can rewrite it to use Tan and Sin or Tan and Cos. So, not completely off the wrong track.

##### Share on other sites

Ok

thanks to everyone for your help

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

## Create an account

Register a new account

×

• Wiki

• Back

• Git