Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Math.atan2 Function Explanation

New Here ,
Mar 07, 2009 Mar 07, 2009
Hello guys
This is a piece of code from AS3 Making Things Move
I tried to understand what actually atan2 does?

Please explain

Hopefully, ill get help from here :)

Thanks in advance
TOPICS
ActionScript
5.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 07, 2009 Mar 07, 2009
that's pretty accurate.

if you remember from trigonometry, the tangent of an angle (theta) formed by the x-axis and a line from (0,0) to (x,y) is y/x. ie, tan(theta) = y/x.

and the arctan is just the inverse: given the number y/x, what's the angle? ie, arctan(y/x) = theta.

in mos' code (dx,dy) can be considered a point on a cartesian coordinate system. if you draw a line from the (0,0) to (dx,dy) that line intersects the x-axis and forms an angle with the x-axis. that angle is the inverse ta...
Translate
LEGEND ,
Mar 07, 2009 Mar 07, 2009
If this is a trigonometry wondering, you can look up atan2 via Google and try to find an explanation that makes sense to you (it can be hard to explain in simple terms by words alone). Here's a link to what Wikipedia has to say: http://en.wikipedia.org/wiki/Atan2

In the simplest of terms for the code shown, what it's doing is telling you the angle (in radians) of the mouse relative to the x and y location of an arrow (likely the axis of rotation).
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 09, 2009 Mar 09, 2009
Thanks for your replies,
I tried to explain what i learnd from ur discussion
Please correct me if i am wrong

Due to u guys, i could learn these difficult things

Thanks once again :)


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 07, 2009 Mar 07, 2009
Many Thanks :)
Pretty bad with Math
so u have to tolerate me for a while.


I mean, how dy and dx forms a triangle? are not they at the same point :/
this is where im struck !
can u jst visualize this things in words?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 07, 2009 Mar 07, 2009
I'm no math expert either, so if I'm off in this attempt, a more accurate description is welcome. The part I won't be able to explain is the atan2 bit itself.

If you look at dx and dy, they are not points, but the distance between two points. So you have an x-related distance of dx, and a y-related distance dy (the "d" is also often referred to as "delta", or "the change in").

When you take the x-length and intersect it with the y-length, you end up with a right angle. The rest is where I best not tread trying to explain, just accept that the atan2 relates to those lengths, possibly providing the angle of a line that would join them from the 0,0 axis to the opposite corner were you to make a rectangle of it.

While I prefer to not drop names, there is one person I can think of in these forums that likely understands this like we understand tomorrow is Sunday. Maybe he'll stop in and give it a shot.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 07, 2009 Mar 07, 2009
that's pretty accurate.

if you remember from trigonometry, the tangent of an angle (theta) formed by the x-axis and a line from (0,0) to (x,y) is y/x. ie, tan(theta) = y/x.

and the arctan is just the inverse: given the number y/x, what's the angle? ie, arctan(y/x) = theta.

in mos' code (dx,dy) can be considered a point on a cartesian coordinate system. if you draw a line from the (0,0) to (dx,dy) that line intersects the x-axis and forms an angle with the x-axis. that angle is the inverse tangent (arctan) of dy divided by dx (dy/dx).

flash, in addition to having a Math.atan(y/x) function also has an atan2 function Math.atan2(y,x) that accepts two parameters so no division is needed.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 07, 2009 Mar 07, 2009
Thanks for stopping in... I was hoping you might. If I remembered much of anything from trig, I might have stood a chance at providing the proper explanation, but I'd still probably have to blow the dust off some old textbooks.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 09, 2009 Mar 09, 2009
Sorry, these right side of the monitor got messed (containing = symbols)
but else is quite clear.
Thanks in advance
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 09, 2009 Mar 09, 2009
no.

the x-axis is a horizontal line that runs through the origin (0,0).

draw a line from 0,0 to Mx,My
draw a line from 0,Mx to Mx,My

that forms the relevant triangle. the relevant angle is the angle formed by the line from 0,0 to Mx,My and the x-axis.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 09, 2009 Mar 09, 2009
Is this right now?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 10, 2009 Mar 10, 2009
@kglad
Please Confirm it
As i cant trust on my personal judgment !
Thanks
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 10, 2009 Mar 10, 2009
1- looks ok

2- looks more like a line from Mx,0 to Mx,My

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 10, 2009 Mar 10, 2009
Thanks, ill come up with some sin cosin questions too
hopefully, ull help in those matters too 🙂
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 10, 2009 Mar 10, 2009
LATEST
you're welcome,
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines