Don*_*eld 25 math arguments conventions
在C中,atan2函数具有以下签名:
double atan2( double y, double x );
Run Code Online (Sandbox Code Playgroud)
其他语言也这样做.这是我所知道的唯一一个以Y,X顺序而不是X,Y顺序获取其参数的函数,它会使我经常搞砸,因为当我想到坐标时,我认为(X,Y).
有谁知道为什么atan2的参数顺序约定是这样的?
Not*_*ure 12
我的假设一直是因为三角定义,即那个
tan(theta) = opposite / adjacent
Run Code Online (Sandbox Code Playgroud)
使用来自原点的规范角度时,相反的是始终为Y且相邻始终为X,因此:
atan2(opposite, adjacent) = theta
Run Code Online (Sandbox Code Playgroud)
也就是说,它是这样完成的,因此在数学定义方面没有排序混乱.