Sign in to follow this  
Followers 0
Jonas93

Need help with geometry-Funktion

3 posts in this topic

Hi,

Take a look at this script

Func _getTurnLine($a,$x,$y,$m)
local $turnLine[2]
$deg = 4*Atan(1) / 180
$angle = $a * $deg
$turnLine[0] = tan($angle + ATan($m))
$turnLine[1] = $y - ($turnLine[0] * $x)
return $turnLine
EndFunc

Using it to turn a line at $a degrees.

Try out this: _getTurnLine(45,2,2,0)

$array[0] should be 1 (successfull) and $array[1] should be 0 but $array[1] gives out a freaking number with "e-106".

plz help :graduated:

Share this post


Link to post
Share on other sites



Jonas93,

Welcome to the AutoIt forum. :graduated:

Could you please explain what the function does, what the 4 parameters represent, and what should be in the 2 elements of the returned array. It would make helping you much easier as we might then have a clue as to what you were doing! ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Func _getTurnLine($a, $x, $y, $m)
Local $turnLine[2]
Local $pi = 3.14159265358979
$deg = $pi / 180
$angle = $a * $deg
$turnLine[0] = Round(Tan($angle + ATan($m) / $deg))
$turnLine[1] = Round($y - $turnLine[0] * $x)
Return $turnLine
EndFunc ;==>_getTurnLine

If you want to just rotate a line, here's an example:

#include <GUIConstantsEx.au3>

_Test()
Func _Test()
Local $hGUI = GUICreate("Test", 450, 450)
GUISetBkColor(0xffffff)
Local $Graphic2 = GUICtrlCreateGraphic(225, 225, 200, 200)
GUICtrlSetGraphic($Graphic2, $GUI_GR_PENSIZE, 2)
GUICtrlSetGraphic($Graphic2, $GUI_GR_COLOR, 0x996600)

For $i = 0 To 170 Step 10
Local $aV = _RotateLine($i, 0, 0, 200, 0, False)
;set the initial point
GUICtrlSetGraphic($Graphic2, $GUI_GR_MOVE, $aV[0], $aV[1])
;draw the line to the final point
GUICtrlSetGraphic($Graphic2, $GUI_GR_LINE, $aV[2], $aV[3])
__Debug("x=" & $aV[2] & ", y=" & $aV[3])
Next

GUISetState()

While 1
Sleep(10)
Switch GUIGetMsg()
Case -3
Exit
EndSwitch
WEnd
EndFunc ;==>_Test

Func _RotateLine($iAngle, $iX0, $iY0, $iX, $iY, $bClockwise = True)
Local $aRet[4]
Local $PI = 3.14159265358979
Local $DEG2RAD = $PI / 180
$iAngle = $iAngle * $DEG2RAD
$iIp = Round(Sqrt(($iX - $iX0) ^ 2 + ($iY - $iY0) ^ 2))
$aRet[0] = $iX0
$aRet[1] = $iY0
$aRet[2] = Round($iIp * Cos($iAngle))
If $bClockwise Then
$aRet[3] = Round($iIp * Sin($iAngle))
Else
$aRet[3] = -Round($iIp * Sin($iAngle))
EndIf

Return $aRet
EndFunc ;==>_RotateLine

Func __Debug($s)
ConsoleWrite($s & @CRLF)
EndFunc ;==>__Debug
Edited by taietel

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