• 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.

Atan2

Status
Not open for further replies.
The tangent function in trigonometry is used to calculate the ratio of a right triangle's opposite leg to its adjacent leg, given the central angle of the right triangle.

Likewise, the ARC tangent function is used to calculate the central angle of a right triangle given the ratio of the triangle's opposite leg to its adjacent leg.

From this you should see that tangent and arctangent are inverses of one another - in fact, Atan is often written in math like Tan^-1 (they are synonymous)

Hence, Atan(y/x) results in the angle of a right triangle with central angle at the origin, right angle on the x axis, height y, and width x.

The only issue with this is the fact that if y or x are negative (or both are negative), the value given to Atan can be misinterpreted, and so although the angle is correct, its phase might not be the desired value!

Atan2 to the rescue. Atan2 accepts the y and x values as separate parameters, and so returns a value on [0,2pi] - extremely useful for scripters working in space.

For an example, take a look at the definition of AngleBetweenPoints() included in blizzard.j (JNGP has a function list that can display it)
 
Status
Not open for further replies.
Top