Firstly, this may sound very trivial, but currently I am creating a function getQuadrant(degree) for returning a quadrant from a given angle.
For instance, if degree is >= 0 and < 90, it will return 1. If degree is >= 90 and < 180, it will return 2. And so forth. This is very trivial. However, to be able to deal with degrees other than 0-360, I simply normalized those numbers to be in 0-360 degree range first, like this:
while (angle > 360)
angle = angle - 360;
end
while (angle < 0)
angle = angle + 360;
end
After that, I calculate. But to be frank, I hate using while statements like this. Are there other mathematical ways that can point out the quadrant of the angle in one go?
EDIT: I see that there are lots of good answers. Allow me to add “which algorithm will be the fastest?“
Take advantage of integer arithmetics:
The idea is, since
angle/360is rounded down (floor()),(angle/360)gives you thekyou need to doalpha = beta + 360k.The second line is normalizing from [-359,-1] back to [1,359] if needed.