For collision testing I need to raster a line. The bresenham algorithm works almost as desired, but has the flaw that is produces a line like:
And I need:
My current implementation (based on http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#Simplification):
public boolean isInsideLine(int x1, int y1, int x2, int y2) {
final int dx = abs(x2 - x1), dy = abs(y2 - y1);
final int sx = x1 < x2 ? 1 : -1, sy = y1 < y2 ? 1 : -1;
int err = dx - dy;
while (true) {
if (isInside(x1, y1)) //Lookup in pixel array
return true;
if (x1 == x2 && y1 == y2)
break;
final int e2 = err << 1;
if (e2 > -dy) {
err -= dy;
x1 += sx;
}
if (e2 < dx) {
err += dx;
y1 += sy;
}
}
return false;
}
Is there an other line rasterization algorithm I could use, or does anyone know how modify the bresenham?