Why are the arguments to atan2 Y,X rather than X,Y?

It's because in school, the mnemonic for calculating the gradient
is rise over run, or in other words dy/dx, or more briefly y/x.

And this order has snuck into the arguments of arctangent functions.

So it's a historical artefact. For me it depends on what I'm thinking
about when I use atan2. If I'm thinking about differentials, I get it right
and if I'm thinking about coordinate pairs, I get it wrong.


Suppose a rectangle triangle with its opposite side called y, adjacent side called x:

tan(angle) = y/x

arctan(tan(angle)) = arctan(y/x)


Because I believe it is related to arctan(y/x), so y appears on top.

Here's a nice link talking about it a bit: Angles and Directions


My assumption has always been that this is because of the trig definition, ie that

tan(theta) = opposite / adjacent

When working with the canonical angle from the origin, opposite is always Y and adjacent is always X, so:

atan2(opposite, adjacent) = theta

Ie, it was done that way so there's no ordering confusion with respect to the mathematical definition.