3

I'm studying a paper in which the author claims to use Bresenham circles to scan the area around a pixel efficiently. I studied the algorithm but the equations used in most websites I've seen are way different from the author's implementation. Have a look:

//center(center.x,center.y) is the circle's center pixel. 
int err = 0;
int dx = _radius;
int dy = 0;
int plus = 1;
int minus = (_radius << 1) - 1;
int olddx = dx;

while (dx>=dy){
    int mask;
    int y=center.y-dy;
    int x=center.x-dx;
    //Found p(x,y).
    //Pixel operations here, not included, not relevant...
    //

    //Now the update. How do they check whether to decrease dx or not??
    dy++;
    err += plus;
    plus += 2;
    
    mask = (err <= 0) - 1;
    
    err -= minus & mask;
    dx += mask;
    minus -= mask & 2;
}

I understand that we only find the pixels of one octant. I understand that we start from (center.x-radius,center.y). So, as we travel along the corresponding octant, dy always increases but dx needs to pass a test to decrease. I've been trying to figure out how the test is done here but with no luck.

plus, minus, mask, err

What do these represent? Any ideas? It's either a simplification of Bresenham's circle algorithm for a faster scan with less computations or a completely different one?

I think I can only understand how mask is defined. If the error err(which we usually have formulas for) is negative, dx stays the same according to the Bresenham algorithm. mask makes sure this is the case here as well. As for how the error is calculated here and how it's connected to plus and minus, I have no idea.

John Katsantas
  • 571
  • 6
  • 20
  • I feel that this is some hacky C code for normal algorithm. If there is no answer within next two weeks I'll try solve it. – R2RT Aug 11 '21 at 16:12

0 Answers0