int quadrant(double x, double y)
{
static int q[]={3, 4, 2, 1};
int sx = ((int)(x/fabs(x)) + 1)/2;
int sy = ((int)(y/fabs(y)) + 1);
return q[sx+sy];
}
you may use, as well,
atan2
instead of
fabs
:
int quadrant(double x, double y)
{
static int q[]={3, 4, 2, 1};
int i = (int)((atan2(y,x)/atan2(1.,0.))+2.0);
return q[i];
}
Please note, the function gives wrong result for
x=0.0
or/and
y=0.0
input values (such points are on the boundary of the quadrants).
:)