## Recommended Posts

I need a bit of math help with Autoit, my math skills are embarrassing. I am trying to convert The Unit Circle to a bearing / angle. I have searched the forms and cant find what Im looking for. I did some research on the web and found the formula but Im not sure how to use them with Autoits math functions.

I would be grateful for any help thx. ##### Share on other sites

I did my Trig crash course online. Im not sure how I got it working but it does what I need now. Its not a prettiest script but it works. xyplane.au3

##### Share on other sites

I did my Trig crash course online. Im not sure how I got it working but it does what I need now. Its not a prettiest script but it works. xyplane.au3

Not sure if it's what you are trying to do, but we had a thread earlier about uses for ATAN() and I wrote a function to take Relative XY coordinates and translate them to polar (theta and radius):

```; Test _xy2polar() UDF
; PsaltyDS at AutoIT forums, 2006-01-26

While (1)
\$InputX = InputBox("Trig Test", "Enter value for X: ")
If \$InputX = "" Then Exit
\$InputY = InputBox("Trig Test", "Enter value for value for Y: ")
If \$InputY = "" Then Exit
\$Results = _xy2polar(\$InputX, \$InputY)
\$SavError = @error
If IsArray(\$Results) Then
If MsgBox(32 + 1, "Function _xy2polar()", "Using the following inputs:" & @CRLF & _
@TAB & "X = " & \$InputX & @CRLF & _
@TAB & "Y = " & \$InputY & @CRLF & @CRLF & _
"Calculated the following values:" & @CRLF & _
@TAB & "R = " & \$Results & @CRLF & _
@TAB & "Theta(Radians) = " & \$Results & @CRLF & _
@TAB & "Theta(Degrees) = " & \$Results) = 2 Then ExitLoop
Else
MsgBox(16, "XY-2-Polar Error", "Error returned from _xy2polar() function, @Error = " & \$SavError)
EndIf
WEnd

; User Declared Function (UDF) _xy2polar() - calculates polar coordinates (r, Theta) from cartesean (x, y) coordinates
;   Usage:  _xy2polar(\$x, \$y)  where:  \$x and \$y are signed X and Y coordinates (int or float) with a 0,0 center
;   Returns:  Three element one-dimensional array where:
;                = Calculated radius from 0,0
;                = Theta angle in radians, 0 <= Theta < 2(Pi)
;                = Theta angle in degrees, 0 <= Theta < 360
;   On error:  Returns "", and @error = 1

Func _xy2polar(\$x, \$y)
\$Pi = 4 * ATan(1)
If StringIsInt(\$x) Or StringIsFloat(\$x) Then
If StringIsInt(\$y) Or StringIsFloat(\$y) Then
; OK
Else
SetError(1)
Return ""
EndIf
Else
SetError(1)
Return ""
EndIf
\$r = Sqrt((\$x ^ 2) + (\$y ^ 2))
Select
Case \$x = 0 And \$y = 0
Case \$x >= 0 And \$y >= 0 ; +x/+y = 0-90deg quadrant
Case \$x >= 0 And \$y < 0 ; +x/-y = 90-180deg quadrant
Case \$x < 0 And \$y < 0 ; -x/-y = 180-270deg quadrant
Case \$x < 0 And \$y >= 0 ; -x/+y = 2700-360deg quadrant
EndSelect
SetError(0)
EndFunc   ;==>_xy2polar```

Cheers! Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

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