<p>i have this bresenham's code, but actually this work only to some cases, how can i complete to any cases?</p>
<pre><code>    this.dx = dx;
    this.dy = dy;

    int m = dy / dx;
    if (dx &gt;= 0 &amp;&amp; dy &gt;= 0) {
        if (m &lt; 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;
        }
    }
</code></pre>
<p>will be that repeat this code 3 times over?
to following cases?</p>
<pre><code>if (dx &gt; 0 &amp;&amp; dy &lt; 0)
if (dx &lt;= 0 &amp;&amp; dy &lt;= 0)
if (dx &lt; 0 &amp;&amp; dy &gt; 0)
</code></pre>
<p>actually only works for the first quadrant</p>
<pre><code>       +
       +   here worked
       +
+++++++++++++++++
       +
       +
</code></pre>

CC BY-SA 4.0
2020-09-02T05:37:04.710Z
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.
wychmaster
CC BY-SA 4.0
2020-09-02T05:41:15.730Z
@wychmaster i edited my question
hubman
CC BY-SA 4.0
2020-09-02T07:11:24.290Z
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](https://www.geeksforgeeks.org/bresenhams-circle-drawing-algorithm/).
wychmaster
<algorithm>
How can i use bresemhan to any cases?
hubman
# How can i use bresemhan to any cases?

(Asked by: username_0 on 2020-09-02)

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
       +
+++++++++++++++++
       +
       +

```

**Tags:** algorithm

> **Comments:**
> **username_1**: 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.  
> **username_0**: @username_1 i edited my question  
> **username_1**: 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](https://www.geeksforgeeks.org/bresenhams-circle-drawing-algorithm/).  

---

## 0 answers

