Hey guys, I’ve spend way too much time trying to make Bresenhem’s midpoint line algorithm to work in every octant. Can someone pleaseee edit my code so it work on all 8 octants. Right now it only work in octant 1,2,4,5, and 8. I count the octants from 1 - 8 counter-clockwise starting right above the positive X-axis. I think i’ve complicated things!!! helpppp!! You can even completely switch up my code if you want to, I’ve 30 hours on something that shouldn’t take me more than 5 hours.
void drawLine(int Ax, int Ay, int Bx, int By)
{
int y,x, dy, dx, slope, decision, incE, incNE;
int temp;
if (Ax > Bx)
{
temp = Ax;
Ax = Bx;
Bx = temp;
temp = Ay;
Ay = By;
By = temp;
}
dx = Bx - Ax;
dy = By - Ay;
if (dy < 0)
{
slope = -1;
dy = -dy;
}
else
{
slope = 1;
}
if(Ay == By)
{
y = Ay;
for (x = Ax; x != Bx; x++)
setCell(x,y,0.4,0.7,1.0);
return;
}
if(Ax == Bx)
{
x = Ax;
if(Ay > By)
{
temp = Ay;
Ay = By;
By = temp;
}
for (y = Ay; y<= By; y++)
setCell(x,y,0.4,0.7,1.0);
return;
}
incE = 2 * dy;
incNE = 2 * dy - 2 * dx;
decision = 2 * dy - dx;
if( dy > dx)
{
incE = 2*dx;
incNE = 2*dx - 2 *dy;
x = Ax;
printf("test1
");
for (y = Ay; y <= By; y++)
{
setCell(x,y, 0.4, 0.7, 1.0);
if (decision <= 0)
decision += incE;
else
{
decision += incNE;
x++;
}
}
return;
}
y = Ay;
for (x = Ax; x <= Bx; x++)
{
setCell(x,y, 0.4, 0.7, 1.0);
if (decision <= 0)
{
decision += incE;
}
else
{
decision += incNE;
y += slope;
}
}