EDIT: obviously I've made ann error in atan2
after many different approaches, but still curious to find formulas.
I've read multiple topics and articles, yet do not understand why atan and atan2 give different results after convertion into degrees. Here is my example (from CIElab colour space) x -79.7751, y 2.677374209
. Calculation without any changes to code will give incorrect value in both cases:
atan(-79.7751 / 2.677374209) = -1,537 / or in degrees -88,07778762
atan2(-79.7751 , 2.677374209) = 3,1258 / or in degrees 179,0965
However, that example is from an article so we can check results. Basically answer should be 271.9222
. I've found over the internet correction for atan
, now I've got same results, yet I still have indeterminate value for x=y=0
in atan
, hence some corrections should be made for atan2
. Unfortunately I did not found any that would yield same result and and would be proven (I mean what could be found in literature). Most sources for CIElab say to use atan2
without any corrections and as you can below it is not correct in my particular case. Here is what I got on this:
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 of atan2
to get proper results?
Your formulas may be wrong, depending on the library you use. See the C++ std for atan and atan2:
atan(y/x) returns in range {-pi/2, pi/2}
atan2(y,x) returns in range {0, 2pi}
You have exchanged x,y
in both cases. This has the effect of this figure: