From Temperature Curves to Ceramic Dots
Watch a ceramic mug emerge from an engraving machine, its surface now decorated with the precise temperature curve from yesterday’s coffee roast. But here’s the rub: your digital temperature profile is a smooth mathematical function, while your engraving tool can only place discrete marks at specific coordinates. How do you bridge that gap?
Enter Bresenham’s line algorithm, the unsung hero of every CNC machine and laser engraver. Developed in 1962 for early computer graphics, it solves a deceptively simple problem: given two points, which pixels should you light up to draw the straightest possible line between them?
proc bresenham {x0 y0 x1 y1} {
set dx [expr abs($x1 - $x0)]
set dy [expr abs($y1 - $y0)]
set sx [expr {$x0 < $x1 ? 1 : -1}]
set sy [expr {$y0 < $y1 ? 1 : -1}]
set err [expr $dx - $dy]
set x $x0; set y $y0
while {$x != $x1 || $y != $y1} {
puts "engrave ($x,$y)"
set e2 [expr 2 * $err]
if {$e2 > -$dy} { incr err [expr -$dy]; incr x $sx }
if {$e2 < $dx} { incr err $dx; incr y $sy }
}
}
def bresenham(x0, y0, x1, y1):
dx, dy = abs(x1 - x0), abs(y1 - y0)
sx, sy = (1 if x0 < x1 else -1), (1 if y0 < y1 else -1)
err = dx - dy
x, y = x0, y0
while x != x1 or y != y1:
yield (x, y)
e2 = 2 * err
if e2 > -dy: err -= dy; x += sx
if e2 < dx: err += dx; y += sy
The magic lies in the error term—it tracks how far we’ve drifted from the ideal line and decides whether to step horizontally, vertically, or diagonally. No floating-point division, no trigonometry, just elegant integer arithmetic that runs in linear time.
Your roasting curve becomes a series of connected line segments, each one discretized into the precise coordinates your engraver needs. The algorithm ensures your ceramic bears the most faithful possible representation of that perfect roast, one calculated dot at a time.