// from mathfuncs_core.cpp of opencv void fastAtan2(const float *Y, const float *X, float *angle, int len, bool angleInDegrees ) { int i = 0; float scale = angleInDegrees ? 1 : (float)(CV_PI/180); for( ; i < len; i++ ) { float x = X[i], y = Y[i]; float ax = std::abs(x), ay = std::abs(y); float a, c, c2; if( ax >= ay ) { c = ay/(ax + (float)DBL_EPSILON); c2 = c*c; a = (((atan2_p7*c2 + atan2_p5)*c2 + atan2_p3)*c2 + atan2_p1)*c; } else { c = ax/(ay + (float)DBL_EPSILON); c2 = c*c; a = 90.f - (((atan2_p7*c2 + atan2_p5)*c2 + atan2_p3)*c2 + atan2_p1)*c; } if( x < 0 ) a = 180.f - a; if( y < 0 ) a = 360.f - a; angle[i] = (float)(a*scale); } }