My atan2 function:

proc |

Here's small visualization what values it returns:

I'll refer to this image:

Red vector (named direction) is direction

Two blue vectors represent range where I want to do something

α (alpha) is "falloff" of direction

Purple vector (v) is the vector which I need to check if it's between two blues.

In other words, I need to check if (v) is between (direction-α) and (direction+α)

Here's what I have atm:

for(var/L in b) |

In this piece of code, dirX and dirY are x/y values of (v), 'angle' is angle in degrees of my (v), (L.direction - L.angle/2) and (L.direction + L.angle/2) are (direction-α) and (direction+α).

Code works fine, unless my direction is 180 degree (the -y direction). It checks correctly when (v) is <180, but makes mistake when (v) > -180.

I'm sorry if I failed to explain.

Thank you in advance.

Let a1 be the angle of the alpha vector on the left (- alpha) side of d, a2 be the angle of the alpha vector on the right (+ alpha) side.

Let v be the angle of the vector you're testing.

That should work (completely untested) assuming that alpha < 90, also assuming angles are in degrees. Conversion to radians is easy enough.

Basically it works by making a1 the zero point and then checking if we're within a2. Angles are fiddled with such that being pushed past -180 or 180 flips sign appropriately. The reason it doesn't work for cases where alpha is >= 90 is because it ends up taking the smaller angle.

Not at all sure if this is the fastest or most correct way to do it, but it feels functional. If you need alpha >= 90, comment again and I'll think about it some more.