I am interested in octants in plane geometry, which basically involves dividing a plane into 8 equal parts according to a certain point.Octants are particularly useful while implementing the Bresenham's algorithm.ProblemGiven two points A = (x1, y1) and B = (x2, y2), how to determine in which octant belongs B according to A?Counting octants is performed as shown: starting from the upper right and iterating anticlockwise.Naive implementationdef get_octant(pA, pB):    AX = pA[0]    AY = pA[1]    BX = pB[0]    BY = pB[1]    if BX > AX:        if BY > AY:            if (BY - AY) < (BX - AX):                octant = 0            else:                octant = 1        else:            if (AY - BY) < (BX - AX):                octant = 7            else:                octant = 6    else:        if BY > AY:            if (BY - AY) < (AX - BX):                octant = 3            else:                octant = 2        else:            if (AY - BY) < (AX - BX):                octant = 4            else:                octant = 5    return octantWould it not possible to find a cleverer implementation?Using the symmetry properties, I am convinced that it is possible to make a shorter and more readable code. Unfortunately, I do not find it myself, so does anyone have an idea, please?
Determining which octant has a specific point
python;algorithm;coordinate system
I am convinced that it is possible to make a shorter and more readable code. To implement the discrete analog of atan2((B.y - A.y), (B.x - A.x)):x, y  = (B.x - A.x), (B.y - A.y)octant = [([1, 2], [8, 7]), ([4, 3], [5, 6])][x < 0][y < 0][abs(x) < abs(y)]It is shorter, I don't know about readability. It is easy to write tests that check all possible variants including the behavior on the boundaries.