Jump to content



Photo

atan2 please :D


  • Please log in to reply
19 replies to this topic

#1 BlindWanderer

BlindWanderer

    Seeker

  • Active Members
  • 22 posts

Posted 31 October 2005 - 01:52 AM

so i'm being bad and doing heavy math in autoit and it would be devine if there was atan2







#2 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,078 posts

Posted 31 October 2005 - 01:57 AM

so i'm being bad and doing heavy math in autoit and it would be devine if there was atan2


Thats part of what is so great about Autoit

You can create UDF's ( User Defined Functions )

Here is your oportunity to be a part of the next release

8)

Posted Image

Clic The Pic!!!


#3 markusss

markusss

    Adventurer

  • Active Members
  • PipPip
  • 139 posts

Posted 31 October 2005 - 01:59 AM

HELP! what the ef-you-see-k is atan2??

I feel so dumb right now, since everybody (ok its _just_ valuater) knows atan2

Felix

#4 markusss

markusss

    Adventurer

  • Active Members
  • PipPip
  • 139 posts

Posted 31 October 2005 - 02:10 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 though... im lost

Felix

Edited by Felix N., 31 October 2005 - 02:12 AM.


#5 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,078 posts

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)

Posted Image

Clic The Pic!!!


#6 markusss

markusss

    Adventurer

  • Active Members
  • PipPip
  • 139 posts

Posted 31 October 2005 - 02:29 AM

Thanks Valuater! B)

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 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,078 posts

Posted 31 October 2005 - 02:43 AM

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)

Edited by Valuater, 31 October 2005 - 02:45 AM.

Posted Image

Clic The Pic!!!


#8 BlindWanderer

BlindWanderer

    Seeker

  • Active Members
  • 22 posts

Posted 31 October 2005 - 03:26 AM

hmm i guess we don't have any programers...

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 jftuga

jftuga

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 315 posts

Posted 31 October 2005 - 03:39 AM

A little off topic....

Compute 4 * atan(1)

:-)

-John

#10 markusss

markusss

    Adventurer

  • Active Members
  • PipPip
  • 139 posts

Posted 31 October 2005 - 03:45 AM

Mhhhhhhm i just love pie, especially fresh apple pie!

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 BlindWanderer

BlindWanderer

    Seeker

  • Active Members
  • 22 posts

Posted 31 October 2005 - 08:29 AM

*twitch twitch* i wasn't expecting atan(1/0) to actualy work. I'm not use to it.

well then nm

oh and i wrote a plugin that handles a few obscure math functions.

Attached Files

  • Attached File  math.zip   54.86KB   320 downloads

Edited by BlindWanderer, 31 October 2005 - 08:37 AM.


#12 Confuzzled

Confuzzled

    Mouse moved. Please restart Windows for changes to take effect.

  • Active Members
  • PipPipPipPipPipPip
  • 1,000 posts

Posted 31 October 2005 - 04:02 PM

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)

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? B) Did you shuffle the punch cards in the output hopper so the other students couldn't reproduce their software masterpieces again? :o

My other computer is an abacus...

#13 BlindWanderer

BlindWanderer

    Seeker

  • Active Members
  • 22 posts

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? B) Did you shuffle the punch cards in the output hopper so the other students couldn't reproduce their software masterpieces again? :o

My other computer is an abacus...


... I was a student of the new age, scientific calculators were manditory in class :graduated:

#14 markusss

markusss

    Adventurer

  • Active Members
  • PipPip
  • 139 posts

Posted 31 October 2005 - 08:33 PM

Lol, we need graphing ones^^

Your math functions look good, might wanna add some more and you might ask one of the devs to implement them...

Felix N

#15 Nutster

Nutster

    Developer at Large

  • Developers
  • 1,450 posts

Posted 04 November 2005 - 09:27 PM

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.
David NuttallNuttall Computer ConsultingAutoIt allows me to re-invent the wheel so much faster.An Aquarius born during the Age of AquariusI'm off to write a wizard, a wonderful wizard of odd...

#16 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 26 January 2006 - 03:58 AM

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.

Ummm... ;)

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:

Plain Text         
; 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! :lmao:
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

#17 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 26 January 2006 - 05:22 PM

Modified my script into a reusable function: _xy2polar($x, $y), where $x and $y are x/y coordinates, and it returns a three element array where:

[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():

CODE

; 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. :lmao:

Edit: Tweaked comments to explain usage and removed redundant declaration of Pi.

Edited by PsaltyDS, 26 January 2006 - 05:36 PM.

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

#18 Gabburd

Gabburd

    Wayfarer

  • Active Members
  • Pip
  • 69 posts

Posted 09 January 2008 - 07:59 AM

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


#19 GEOSoft

GEOSoft

    Sure I'm senile. What's your excuse?

  • MVPs
  • 10,565 posts

Posted 09 January 2008 - 02:43 PM

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

Much shorter than the existing _ATan2() (in Math.au3) anyway. Of course the original also has some extra error checking in it.
GeorgeQuestion about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else."Old age and treachery will always overcome youth and skill!"

#20 Gabburd

Gabburd

    Wayfarer

  • Active Members
  • Pip
  • 69 posts

Posted 09 January 2008 - 04:21 PM

Wow, I must be blind not to have noticed that there already was a function in there. :)
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