atan2 please :D
#1
Posted 31 October 2005 - 01:52 AM
#3
Posted 31 October 2005 - 01:59 AM
I feel so dumb right now, since everybody (ok its _just_ valuater) knows atan2
Felix
#4
Posted 31 October 2005 - 02:10 AM
arctangent(=inverse tangent) with double values
to get the arctangent you do this in autoit:
ATan( expression )
I still don't get the "double" part though... im lost
Felix
Edited by Felix N., 31 October 2005 - 02:12 AM.
#5
Posted 31 October 2005 - 02:14 AM
ok i found out that atan2 is:
arctangent(=inverse tangent) with double values
to get the arctangent you do this in autoit:
ATan( expression )
I still don't get the "double" part
hey Felix... you dont need to post about how " dumb" you are or feel
i wish newbies showed half of the effort you do in "finding" the answer to something you dont know...
and that is definetly "not dumb"
8)
#6
Posted 31 October 2005 - 02:29 AM
But.... Lol, i still don't get the double thingy, read/googled about it for like 15 mins.... do you know what that is valuater, or could you tell me what what you would do with atan2 (<- i kinda like that word^^)?
Felix N
#7
Posted 31 October 2005 - 02:43 AM
i was the only one in my Technical Math college class whom did not have to take the final exam because i past every test with 100% during the semester
... but that was in... um... what year now......like....aaaaa
1974
i did know what it meant.... not the formula
8)
Edited by Valuater, 31 October 2005 - 02:45 AM.
#8
Posted 31 October 2005 - 03:26 AM
atan2(y, x) is basicly the same as atan(y/x) except when x equals zero
http://www.redbrick.dcu.ie/help/reference/...ction.atan2.htm
some programing languages don't bother to define atan and only have atan2
#9
Posted 31 October 2005 - 03:39 AM
Compute 4 * atan(1)
:-)
-John
#10
Posted 31 October 2005 - 03:45 AM
Ok BTT:
atan2(y, x) is basicly the same as atan(y/x) except when x equals zero
There we have the answer to the problem, since we have atan(expression) in autoit
Felix N.
#11
Posted 31 October 2005 - 08:29 AM
well then nm
oh and i wrote a plugin that handles a few obscure math functions.
Attached Files
Edited by BlindWanderer, 31 October 2005 - 08:37 AM.
#12
Posted 31 October 2005 - 04:02 PM
Did your slide rule have the atan2 function engraved on it? Were you allowed to bring your expensive four function calculator to class and actually use it in the tests? Did you sneakily replace it with a scientific one when they first came out and scrunch it back into the original carry case so others wouldn't be suspicious?no... i actually cannot ( not any more )
i was the only one in my Technical Math college class whom did not have to take the final exam because i past every test with 100% during the semester
... but that was in... um... what year now......like....aaaaa
1974
i did know what it meant.... not the formula
8)
My other computer is an abacus...
#13
Posted 31 October 2005 - 07:47 PM
Did your slide rule have the atan2 function engraved on it? Were you allowed to bring your expensive four function calculator to class and actually use it in the tests? Did you sneakily replace it with a scientific one when they first came out and scrunch it back into the original carry case so others wouldn't be suspicious?
Did you shuffle the punch cards in the output hopper so the other students couldn't reproduce their software masterpieces again?
![]()
My other computer is an abacus...
... I was a student of the new age, scientific calculators were manditory in class
#14
Posted 31 October 2005 - 08:33 PM
Your math functions look good, might wanna add some more and you might ask one of the devs to implement them...
Felix N
#15
Posted 04 November 2005 - 09:27 PM
We are currently in a feature freeze awaiting the next release; we are supposed to be just doing bug fixes at this point, but one of us developers might slip it in. If not, I can slip it into the first beta after the release.
#16
Posted 26 January 2006 - 03:58 AM
Ummm...Ok, for those that want more details, atan2(y,x) is a little different from atan(y/x) in that atan() just gives you the slope of the line, mapping into the first or fourth co-ordinates, between -pi/2 to +pi/2. atan2() can give an angle between 0 and 2pi (will include 0, but not 2pi).
We are currently in a feature freeze awaiting the next release; we are supposed to be just doing bug fixes at this point, but one of us developers might slip it in. If not, I can slip it into the first beta after the release.
The AutoIT ATan() function gives the angle in radians for the ratio of Opp/adj sides. I had to look this forgotten trig stuff up (Google truly is your friend), and ask my son (who is taking trig) to get this working. This script takes manual input for X and Y as signed integers and returns the angle (Theta) after converting to degrees. I did X and Y as integers instead of floating point because the point was to calculate angles from mouse coordinates relative to a predefined origin:
; Test calculate Theta from cartesean coordinates Dim Const $Pi = 4 * ATan(1) $x = InputBox("Trig Test", "Enter value for X: ") If Not StringIsInt($x) Then MsgBox(16, "Trig Test", "Invalid value for X!") Exit EndIf $y = InputBox("Trig Test", "Enter value for value for Y: ") If Not StringIsInt($y) Then MsgBox(16, "Trig Test", "Invalid Y!") Exit EndIf $r = Sqrt(($x ^ 2) + ($y ^ 2)) MsgBox(32, "Trig Test", "Using the following values:" & @CRLF & _ "Const Pi: " & $Pi & @CRLF & _ "Input X: " & $x & @CRLF & _ "Input Y: " & $y & @CRLF & _ "Calculated R: " & $r) Select Case $x = 0 And $y = 0 $Theta = 0 Case $x >= 0 And $y >= 0; +x/+y = 0-90deg $Theta = ATan($x / $y) * 180 / $Pi Case $x >= 0 And $y < 0; +x/-y = 90-180deg $Theta = (ATan(Abs($y) / $x) * 180 / $Pi) + 90 Case $x < 0 And $y < 0; -x/-y = 180-270deg $Theta = (ATan(Abs($x) / Abs($y)) * 180 / $Pi) + 180 Case $x < 0 And $y >= 0; -x/+y = 2700-360deg $Theta = (ATan($y / Abs($x)) * 180 / $Pi) + 270 EndSelect MsgBox(32, "Trig Test", "Theta = " & $Theta)
Had to decalcify some old brain cells to do this... good exercise!
#17
Posted 26 January 2006 - 05:22 PM
[0] = calculated radius
[1] = calculated Theta (in radians)
[2] = calculated Theta (in degrees)
If you want to get 360deg functionality, you have to be aware of signed x/y values:
0,0 = center
0, +y = 0deg
+x, 0 = 90deg
0, -y = 180deg
-x, 0 = 270deg
My shot at this is _xy2polar():
; 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[0] & @CRLF & _
@TAB & "Theta(Radians) = " & $Results[1] & @CRLF & _
@TAB & "Theta(Degrees) = " & $Results[2]) = 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:
; [0] = Calculated radius from 0,0
; [1] = Theta angle in radians, 0 <= Theta < 2(Pi)
; [2] = 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
Dim $PolarAnswer[3] ; $Results[0]=Radius, [1]=Theta (in Radians), [2]=Theta (in Degrees)
$r = Sqrt(($x ^ 2) + ($y ^ 2))
$PolarAnswer[0] = $r
Select
Case $x = 0 And $y = 0
$ThetaRad = 0
$ThetaDeg = 0
Case $x >= 0 And $y >= 0 ; +x/+y = 0-90deg quadrant
$ThetaRad = ATan($x / $y)
$ThetaDeg = $ThetaRad * 180 / $Pi
Case $x >= 0 And $y < 0 ; +x/-y = 90-180deg quadrant
$ThetaRad = ATan(Abs($y) / $x)
$ThetaDeg = $ThetaRad * 180 / $Pi + 90
$ThetaRad = $ThetaRad + $Pi / 2
Case $x < 0 And $y < 0 ; -x/-y = 180-270deg quadrant
$ThetaRad = ATan(Abs($x) / Abs($y))
$ThetaDeg = $ThetaRad * 180 / $Pi + 180
$ThetaRad = $ThetaRad + $Pi
Case $x < 0 And $y >= 0 ; -x/+y = 2700-360deg quadrant
$ThetaRad = ATan($y / Abs($x))
$ThetaDeg = $ThetaRad * 180 / $Pi + 270
$ThetaRad = $ThetaRad + 3 * $Pi / 2
EndSelect
$PolarAnswer[1] = $ThetaRad
$PolarAnswer[2] = $ThetaDeg
SetError(0)
Return $PolarAnswer
EndFunc ;==>_xy2polar
I'm pretty new with AutoIT, and would love to hear pointers/critiques.
Edit: Tweaked comments to explain usage and removed redundant declaration of Pi.
Edited by PsaltyDS, 26 January 2006 - 05:36 PM.
#18
Posted 09 January 2008 - 07:59 AM
Func ATan2($x, $y) Local Const $PI = 3.14159265358979 If $y < 0 Then Return -ATan2($x, -$y) ElseIf $x < 0 Then Return $Pi - ATan(-$y / $x) ElseIf $x > 0 Then Return ATan($y / $x) ElseIf $y <> 0 Then Return $Pi / 2 Else MsgBox( 16, "Error - Division by zero", "Domain Error in Function: ATan2()" & @LF & "$x and $y cannot both equal zero" ) SetError( 1 ) EndIf EndFunc
#19
Posted 09 January 2008 - 02:43 PM
Much shorter than the existing _ATan2() (in Math.au3) anyway. Of course the original also has some extra error checking in it.Just in case anyone still needs this, here's what I ended up with:
Func ATan2($x, $y) Local Const $PI = 3.14159265358979 If $y < 0 Then Return -ATan2($x, -$y) ElseIf $x < 0 Then Return $Pi - ATan(-$y / $x) ElseIf $x > 0 Then Return ATan($y / $x) ElseIf $y <> 0 Then Return $Pi / 2 Else MsgBox( 16, "Error - Division by zero", "Domain Error in Function: ATan2()" & @LF & "$x and $y cannot both equal zero" ) SetError( 1 ) EndIf EndFunc
#20
Posted 09 January 2008 - 04:21 PM
I think I'll switch to using it, as you said it has more error checking.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users






