Sign in to follow this  
Followers 0
torels

A little trigonometry help

6 posts in this topic

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 :P

thanks in advance

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

#include <GDIPlus.au3>
$pi = 3.14159265358979
$degToRad = $pi / 180
$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 this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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 this post


Link to post
Share on other sites

Thanks weaponx. Nice example :P

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 this post


Link to post
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 :P

thanks in advance

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

#include <GDIPlus.au3>
$pi = 3.14159265358979
$degToRad = $pi / 180
$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
$degToRad = $pi / 180
$GUI = GUICreate("",600,600)
GUISetState()
_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($GUI)

_GDIPlus_GraphicsFillRect($hGraphics,300,300,2,2)
$radius = 10
For $i = 0 to 360
    _GDIPlus_GraphicsClear($hGraphics,0xFFFFFFFF)
    $x = $radius*cos($i*$degToRad)
    $y = $Radius*sin($i*$degToRad)
   ;$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 this post


Link to post
Share on other sites

Ok :P

thanks to everyone for your help :unsure:


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 this post


Link to post
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
Sign in to follow this  
Followers 0