0
$\begingroup$

i have this bresenham's code, but actually this work only to some cases, how can i complete to any cases?

    this.dx = dx;
    this.dy = dy;

    int m = dy / dx;
    if (dx >= 0 && dy >= 0) {
        if (m < 1) {
            stepX = 1;
            stepY = 1;
            d = 2 * dy - dx;
            de = 2 * dy;
            dne = 2 * (dy - dx);
        } else {
            stepX = 1;
            stepY = 1;
            d = dy + (2 * (-dx));
            de = 2 * (-dx);
            dne = 2 * (dy - dx);
            de = -de;
            dne = -dne;
        }
    }

will be that repeat this code 3 times over? to following cases?

if (dx > 0 && dy < 0)
if (dx <= 0 && dy <= 0)
if (dx < 0 && dy > 0)

actually only works for the first quadrant

       +
       +   here worked
       +
+++++++++++++++++
       +
       +
$\endgroup$
  • $\begingroup$ Can you specify in which cases it works and in which cases it fails? What is the result if it fails? Those details might help to find the problem faster. $\endgroup$ – wychmaster Sep 2 at 5:37
  • $\begingroup$ @wychmaster i edited my question $\endgroup$ – hubman Sep 2 at 5:41
  • $\begingroup$ I currently don't have the time to double-check my claims and write a proper answer, but as far as I can remember, the algorithm is only supposed to work for the first octant starting at x=0 and y=+a where a is an arbitrary number. You can get the values for all other octants by abusing the symmetry of the circle. Have a look into this link. $\endgroup$ – wychmaster Sep 2 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.