Bresenham developed an algorithm for drawing straight lines
on a raster device. This algorithm uses integer arithmetic only and is faster
and more accurate than the more obvious algorithms that use floating-point arithmetic.
Most raster devices contain embedded variants of Bresenham's algorithm.
To connect P1 = (x1,y1) with P2 = (x2,y2) on a raster device:
The Algorithm:
var dy = y2-y1 var dx = x2-x1 var d = 2*dy - dx var x = x1 var y = y1 while (x <= x2) { Draw pixel at (x,y) x++ if( d<0 ) d += dy + dy else { d += 2*(dy-dx) y++ } } |