Every line on a computer screen is a lie. A mathematical line is a continuous, infinitely thin ribbon of points. A screen is a grid of square pixels. Drawing a line means deciding which pixels to light up â and making that choice so quickly that the result looks smooth.
In 1962, IBM engineer Jack Bresenham was working with a pen plotter at IBM's San JosĂ© Research Laboratory. Floating-point arithmetic was expensive â or simply unavailable â on the hardware of the day. He needed to trace a straight path across a grid using only the cheapest operation a digital circuit can do: integer addition.
The insight he found is almost embarrassing in its simplicity: instead of computing the exact y-coordinate for every x-step (which requires division), track the accumulated error between the true line and the chosen pixel row. Each step you just add a constant, then check whether the error has crossed a threshold. If it has, step up a row and subtract the threshold. No division, no floating point â just addition and a sign check.
The result is an algorithm that is in the number of pixels and provably optimal: it touches exactly the pixels that best approximate the line, and nothing else.
Comments
Loading comments...