# MidPoint algorithm (2)

What we'd like to do is to use this discriminating function to maintain our trajectory of drawn pixels as close as possible to the desired circle. Luckily, we can start with a point on the circle, (x0, y0+r) (or (0, r) in our adjusted coordinate system). As we move along in steps of x we note that the slope is less than zero and greater than negative one at points in the direction we're heading that are near our known point on a circle. Thus we need only to figure out at each step whether to step down in y or maintain y at each step.

• ### M ouside (f>0) => next point is SE ### D0 = f(1, r-1/2) = 5/4 - r ...not an inger Lets change every where D by P = D - 1/4 P0 = 1 - r , and because increment are always integer, P < -1/4 <=> P < 0

```        int x = 0;        int y = radius;
int p = 1 - radius;        circlePoints(xCenter, yCenter, x, y, pix);        while (x < y) {            x++;            if (p < 0) {                p += 2*x+1;            } else {                y--;                p += 2*(x-y+1);            }            circlePoints(xCenter, yCenter, x, y, pix);        } ```

 Web www.vrarchitect.net