math.atan2 usage question

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
WarBride
Kobold
Posts: 4
Joined: Mon May 02, 2016 11:53 am

math.atan2 usage question

Post by WarBride »

In the release notes for the MapTool 1.4.0.3 Build:
math.atan2 -- A version of atan that takes 2 arguments instead of a ratio so that it can return angle based on signs of inputs (allowing you to determine quadrant). Return is in degrees
I am trying to understand how to use this function. Ultimately, I am trying to return what the angle is between two tokens. What are the two parameters it is expecting?

Any help would be appreciated - thanks for your time.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: math.atan2 usage question

Post by wolph42 »

this i got from one of the devs:
In a variety of computer languages, the function atan2 is the arctangent function with two arguments. The purpose of using two arguments instead of one is to gather information on the signs of the inputs in order to return the appropriate quadrant of the computed angle, which is not possible for the single-argument arctangent function. It also avoids the problems of division by zero.
For any real number (e.g., floating point) arguments x and y not both equal to zero, atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point given by the coordinates (x, y) on it. The angle is positive for counter-clockwise angles (upper half-plane, y > 0), and negative for clockwise angles (lower half-plane, y < 0).
the wiki will be updated with the math functions in due time.

WarBride
Kobold
Posts: 4
Joined: Mon May 02, 2016 11:53 am

Re: math.atan2 usage question

Post by WarBride »

Thank you wolph42. After playing with it a bit more, it became clear what the function needed: just a basic (x,y) point on a Cartesian grid.

The interesting thing is that it returns theta in degrees where 0 degrees is "up" or "north" on the map. A negative theta is rotating left, where a positive theta is rotating right from the 0 degree "up" reference.

However, the getFacing() function returns the facing angle where 0 degrees is "right" or "east" on the map. AND the signs are flipped from behavior shown in the math.atan2() function. GetFacing() returns a negative angle to denote a token rotation to the right while a positive angle denotes a rotation to the left.

It isn't a problem to rotate the orientation to a consistent 0-reference-point and flip the signs as needed, but I was wondering if this is expected behavior?

Again, thanks for your reply above.

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: math.atan2 usage question

Post by aliasmask »

Yeah, that's a quirk of MT. The y-axis is reversed but returning the facing it's done as if it wasn't.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: math.atan2 usage question

Post by wolph42 »

the short of it: getFacing is a FU function, don't use it. In the old days it was the only thing there and it was created the way it works for a convoluted reason that eludes me to this day. I'm actually not sure whether there's already a new function available (ill ask the devs). In case there's not I suggest that you create a conversion function (or use the one provided in the BoT) when you use *that* function you at least get a normal angle.

Post Reply

Return to “Macros”