色差atan和atan2结果差异

Color difference atan and atan2 difference in results

编辑:显然我在 atan2 中犯了一个错误,但我仍然想找到公式。

我阅读了多个主题和文章,但不明白为什么 atan 和 atan2 在转换为度数后给出不同的结果。这是我的示例(来自 CIElab 颜色 spacex -79.7751, y 2.677374209。在这两种情况下,不对代码进行任何更改的计算将给出不正确的值:

atan(-79.7751 / 2.677374209) = -1,537 / or in degrees -88,07778762
atan2(-79.7751 , 2.677374209) = 3,1258 / or in degrees 179,0965

但是,该示例来自 article,因此我们可以检查结果。基本上答案应该是271.9222。我在互联网上找到了 atan 的更正,现在我得到了相同的结果,但是 atanx=y=0 的值仍然不确定,因此应该对 atan2。不幸的是,我没有发现任何会产生相同结果并且会被证明的方法(我的意思是可以在文献中找到的东西)。 CIElab 的大多数来源都说使用 atan2 没有任何更正 并且你可以在下面看到它在我的特定情况下是不正确的。这是我得到的:

atan(-79.7751 / 2.677374209) = -1,537 / for atan < 0 : atan + 2pi
hence atan = 4,7459 / or in degrees 271,922 ( BINGO! )

atan2(-79.7751 , 2.677374209) =  ̶3̶,̶1̶2̶5̶8̶  3,108 / or in degrees  ̶1̶7̶9̶,̶0̶9̶6̶5̶  178,0777876
now convert, for deg > 90 : 450 - deg
atan2 result 271,922

̶A̶s̶ ̶y̶o̶u̶ ̶c̶a̶n̶ ̶s̶e̶e̶,̶ ̶̶c̶l̶o̶s̶e̶ ̶b̶u̶t̶ ̶n̶o̶ ̶c̶i̶g̶a̶r̶̶.̶ ̶A̶l̶s̶o̶ ̶i̶t̶ ̶d̶i̶f̶f̶e̶r̶s̶ ̶b̶y̶ ̶1̶ ̶d̶e̶g̶r̶e̶e̶ ̶a̶n̶d̶ ̶s̶o̶m̶e̶ ̶c̶h̶a̶n̶g̶e̶.̶ My question is how exactly I can make a correction的 atan2 以获得正确的结果?

您的公式可能有误,具体取决于您使用的库。请参阅 atan and atan2 的 C++ 标准:

atan(y/x) returns 在范围 {-pi/2, pi/2}
atan2(y,x) returns 在范围 {0, 2pi}

您在这两种情况下都交换了 x,y。有这个图的效果: