Created
October 11, 2017 21:37
-
-
Save natevm/59f17050f424067a79c029578e9d1aa8 to your computer and use it in GitHub Desktop.
Pseudo-angle method
This file contains hidden or 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
// angle relative to the x axis. | |
inline float pseudoangle(float2 p1, float2 p2) { | |
float dx, dy, t; | |
dx = p2.x - p1.x; | |
dy = p2.y - p1.y; | |
if ((dx == 0.0) && (dy == 0.0)) { | |
return -1; // indicating error | |
} | |
else { | |
t = dy / (fabs(dx) + fabs(dy)); | |
/* Now correct for quadrant -- first quadrant: [0,1] */ | |
if (dx < 0.0) | |
return 2.0 - t; | |
/* Inside second or third quadrant (1,3)*/ | |
else if (dy < 0.0) | |
return 4.0 + t; | |
return t; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment