• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Maths and Jass

Status
Not open for further replies.
Level 16
Joined
Oct 12, 2008
Messages
1,570
Hello people,,

I have had a few questions for a long time, and i have tried to find the answer, but no succes, so i am asking you guys here,,
If i want the angle between 2 point, i need a function,,
I checked the AngleBetweenPoints() function, which just used the Atan2() function,,
But what does Atan2 do? Ya, it calculates angle between 2 points, but how?
I though Atan was from ArcTangent, but why do we have Atan() and Atan2() then?
Then i heard it had something to do with polar coordinates, which involve (r,θ) (r = distance, θ = angle)
So i thought maybe Atan() calculates the 'r' (distance) and Atan2() the 'θ' (angle),, but then i still dont know why they called it Atan, if it calculates the distance, because the distance could be easily calculated with Pytagoras' function,,

So: What ar Atan() and Atan2() for,,
Also, if i want the angle between 2 point, cant i just use this:
set Angle = Acos((GetUnitX(Caster) - GetUnitX(Target))/Distance) * bj_RADTODEG

as well as:
set Angle = Asin((GetUnitY(Caster) - GetUnitY(Target))/Distance) * bj_RADTODEG

Arent these two doing the same as Atan2() ??
(I made them out of the calculation NewX = X + Dist * Cos(a) and NewY = Y + Dist * Sin(a))

Someone please help!

-Yixx,,-
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Ok, but what does Atan do then?
And about the polar coordinates, do Atan() and Atan2() calculate the coordinates?
If so, why does PolarProjectionBJ() not use Atan() and Atan2() instead of Cos() and Sin(),,
 
Level 28
Joined
Mar 25, 2008
Messages
2,955
HINDYhat said:
Here's how you use Atan and Atan2. Say you have a vertical displacement y, and a horizontal displacement x, then the angle of elevation formed by a right triangle with those sides would be Atan(y/x) or Atan2(y, x). Now, the problem with Atan is that if x == 0, then you have a division by 0. The second problem, is what if both y and x are negative values? Atan, in that case, has no way to determine if the angle is in the top right corner of a unit circle, o
The point is that Atan2 will give you the correct angle, always. Atan will give you values between 0 and pi I believe (not too sure about this) because of sign conflicts, whereas Atan2 can give you values from 0 to 2pi.
I'll just leave this here..
 
Status
Not open for further replies.
Top