My atan2 function:
if(dy == 0)
if(dx > 0)
else if(dx == 0)
if(dx == 0)
if(dy > 0)
else if(dy == 0)
var/angle = arctan(dy/dx)
if(dx < 0)
angle = 180 - angle
if(dy < 0)
angle = -angle
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)
dirX = (x + oX + 0.125) - (L.x + 0.5)
dirY = (y + oY + 0.125) - (L.y + 0.5)
angle = arctan2(dirX, dirY)
if(angle < L.direction - L.angle/2 || angle > L.direction + L.angle/2)
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.180>