为什么 atan2 的参数是 Y,X 而不是 X,Y?

发布于 2024-07-25 07:18:26 字数 211 浏览 7 评论 0原文

在 C 中,atan2 函数具有以下签名:

double atan2( double y, double x );

其他语言也这样做。 这是我所知道的唯一一个以 Y,X 顺序而不是 X,Y 顺序获取参数的函数,它经常把我搞砸,因为当我想到坐标时,我想到 (X,Y)。

有谁知道为什么atan2的参数顺序约定是这样的?

In C the atan2 function has the following signature:

double atan2( double y, double x );

Other languages do this as well. This is the only function I know of that takes its arguments in Y,X order rather than X,Y order, and it screws me up regularly because when I think coordinates, I think (X,Y).

Does anyone know why atan2's argument order convention is this way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

安静被遗忘 2024-08-01 07:18:26

因为它与arctan(y/x)有关,所以y先出现。

这是一个很好的链接,对此进行了一些讨论:角度和方向

Because it is related to arctan(y/x), so y appears first.

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

や三分注定 2024-08-01 07:18:26

我的假设一直是,这是因为三角定义,即

tan(theta) = opposite / adjacent

当使用来自原点的正则角度时,相对始终是 Y,相邻始终是 X,所以:

atan2(opposite, adjacent) = theta

即,它是这样做的,因此不会出现顺序混乱关于数学定义。

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.

小瓶盖 2024-08-01 07:18:26

假设一个矩形三角形,其对边称为 y,邻边称为 x:

tan(angle) = y/x

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

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

tan(angle) = y/x

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

貪欢 2024-08-01 07:18:26

因为在学校里,计算梯度的助记符
上升与运行,或者换句话说dy/dx,或者更简单地说是y/x。

这个顺序已经渗透到反正切函数的参数中。

所以它是一个历史文物。 对我来说这取决于我的想法
关于我何时使用atan2。 如果我考虑差异,我就猜对了
如果我考虑的是坐标对,我就错了。

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.

鹤舞 2024-08-01 07:18:26

excel中的顺序是atan2(X,Y),所以我认为相反的顺序是一个编程问题。 通过在“n”和“(”之间放置“2”,并将“/”替换为“,”,只需 2 次操作,即可轻松将 atan(Y/X) 更改为 atan2(Y,X)。相反的顺序需要 4 次操作,并且某些操作会更复杂(剪切和粘贴),

我经常在 Excel 中计算出数学结果,然后将其移植到 .NET,所以有时会挂在 atan2 上,这将是最好的。如果atan2可以以一种或另一种方式标准化。

The order is atan2(X,Y) in excel so I think the reverse order is a programming thing. atan(Y/X) can easily be changed to atan2(Y,X) by putting a '2' between the 'n' and the '(', and replacing the '/' with a ',', only 2 operations. The opposite order would take 4 operations and some of the operations would be more complex (cut and paste).

I often work out my math in Excel then port it to .NET, so will get hung up on atan2 sometimes. It would be best if atan2 could be standardized one way or the other.

负佳期 2024-08-01 07:18:26

如果将 atan2 的参数颠倒过来会更方便。 这样您就无需担心在计算极角时翻转参数。 Mathematica 的等效项就是这样做的: https://reference.wolfram.com/language/ref /ArcTan.html

早在很久以前,FORTRAN 就有一个 ATAN2 函数,其参数顺序不太方便,在 本参考手册,被(有些不准确地)描述为 arctan(arg1 / arg2)。

最初的创建者可能专注于 atan2(arg1, arg2)(或多或少)arctan(arg1 / arg2),并且该决定被盲目地从 FORTRAN 复制到 C、C++、Python、Java 和 JavaScript。

It would be more convenient if atan2 had its arguments reversed. Then you wouldn't need to worry about flipping the arguments when computing polar angles. The Mathematica equivalent does just that: https://reference.wolfram.com/language/ref/ArcTan.html

Way back in the dawn of time, FORTRAN had an ATAN2 function with the less convenient argument order that, in this reference manual, is (somewhat inaccurately) described as arctan(arg1 / arg2).

It is plausible that the initial creator was fixated on atan2(arg1, arg2) being (more or less) arctan(arg1 / arg2), and that the decision was blindly copied from FORTRAN to C to C++ and Python and Java and JavaScript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文