Created
July 13, 2016 14:43
-
-
Save gylns/e3f4ce708d79c468b2569cfaed8f268c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment