Sign in to follow this  
Followers 0
ahmet

Equilateral polylines with GUICtrlSetGraphic

5 posts in this topic

Maybe someone knows how to create equilateral polylines ?

polygon.au3

Share this post


Link to post
Share on other sites



Try this.

#include <GuiConstantsEx.au3>

Local $radius, $n, $polygon_angle, $start_angle, $center_angle, $side, $main, $i, $msg

$main = GUICreate("Test")

$radius = 100
$n = 8 ; <========== Change to number of sides of polygon required.
$polygon_angle = ($n - 2) * 180 / $n
$start_angle = (180 - $polygon_angle) / 2
$center_angle = 180 - $polygon_angle
$side = Sqrt(2 * $radius ^ 2 * (1 - _Cos($center_angle)))

GUICtrlCreateGraphic(0, 0, 200, 200)

;Circle
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0, 0, 2 * $radius, 2 * $radius)

;polygon sides depends on variable, $n.
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $radius + _Cos($start_angle) * $side, 2 * $radius - _Sin($start_angle) * $side)
For $i = 0 To $n
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, $radius + _Cos($start_angle) * $side, 2 * $radius - _Sin($start_angle) * $side)
    $start_angle = $start_angle + 180 - $polygon_angle
Next

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _Cos($angle)
    Local $cos = Cos(4 * ATan(1) * $angle / 180) ; [pi = 4 * ATan(1)]
    If ($angle = 90 Or $angle = 270) Then $cos = 0
    Return $cos
EndFunc ;==>_Cos

Func _Sin($angle)
    Local $sin = Sin(4 * ATan(1) * $angle / 180)
    If ($angle = 180 Or $angle = 360) Then $sin = 0
    Return $sin
EndFunc ;==>_Sin

Share this post


Link to post
Share on other sites

Malkey thnaks for your reply, but that is not what I want.I was trying to create polygon inscribed in circle with desired radius.

Share this post


Link to post
Share on other sites

Malkey thnaks for your reply, but that is not what I want.I was trying to create polygon inscribed in circle with desired radius.

Maybe this sort of thing

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Math.au3>

$radius = 100
$n = 8
$degtorad=atan(1)/45


$polygon_angle = 360/$n
$start_angle = 90 -$polygon_angle/2

$main = GUICreate("Test")

GUICtrlCreateGraphic(0, 0, 200, 200)
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0, 0, 2 * $radius, 2 * $radius)

For $i = 1 To $n
    $x1=$radius + $radius*cos(($start_angle+$i*$polygon_angle)*$degtorad)
    $y1 = $radius + $radius*sin(($start_angle+$i*$polygon_angle)*$degtorad)
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $x1, $y1)
    $x2 = $radius + $radius*cos(($start_angle+($i+1)*$polygon_angle)*$degtorad)
    $y2 = $radius + $radius*sin(($start_angle+($i+1)*$polygon_angle)*$degtorad)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE,$x2, $y2)
Next


GUISetState()


while GUIGetMsg() <> -3
    wend

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

Thanks, that is what I wanted.

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